<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class SGlobal_model extends CI_Model 
{
	function __construct()
	{
		parent:: __construct();
	}
    function getMsisdn($hrid){
        $sql 	= "
            select MSISDN
            from HRS
            where id='$hrid'
        ";
        $query = $this->db->query($sql);
        $res=$query->result_array();
        foreach($res as $nil){
            $hasil=$nil['MSISDN'];
        }
        //var_dump($hasil); exit;
        return $hasil;           
    }
    function getOrg($hrid){
        $sql 	= "
            select ORG
            from HRS
            where id='$hrid'
        ";
        $query = $this->db->query($sql);
        $res=$query->result_array();
        foreach($res as $nil){
            $hasil=$nil['ORG'];
        }
        //var_dump($hasil); exit;
        return $hasil;           
    }
    function getName($hrid){
        $sql 	= "
            select NAME
            from HRS
            where id='$hrid'
        ";
        $query = $this->db->query($sql);
        $res=$query->result_array();
        foreach($res as $nil){
            $hasil=$nil['NAME'];
        }
        //var_dump($hasil); exit;
        return $hasil;           
    }
    function getJobPosition($hrid){
        $sql 	= "
            select JOB_POSITION
            from HRS
            where id='$hrid'
        ";
        $query = $this->db->query($sql);
        $res=$query->result_array();
        foreach($res as $nil){
            $hasil=$nil['JOB_POSITION'];
        }
        //var_dump($hasil); exit;
        return $hasil;           
    }
    function getJob($hrid){
        $sql 	= "
            select JOB
            from HRS
            where id='$hrid'
        ";
        $query = $this->db->query($sql);
        $res=$query->result_array();
        foreach($res as $nil){
            $hasil=$nil['JOB'];
        }
        //var_dump($hasil); exit;
        return $hasil;           
    }
    
	/*********************************************************
	**	MODULE SEARH GLOBAL									**
	**	AUTHOR 			: ANDI SISWANTO						**
	**	DATE CREATED	: 16 Juli 2014 						**
	**	MODIFIED DATE	: 16 Juli 2014						**
	**	MODIFIED BY		: Andi Siswanto						**
	*********************************************************/
    function getSearchMon($Name)
	{ 
		//$sql = "SELECT b.ID, b.NAME FROM LOGINS a, HRS b WHERE NOT b.NAME = 'Administrator' AND a.hr_id = b.id AND LOWER(b.NAME) LIKE LOWER('%".$Name."%')";
        
        $sql = "
            select distinct(PRM_REQUISITION_ID) as ID
            from lkk_fo_det
            where LOWER(PRM_REQUISITION_ID) LIKE LOWER('%".$Name."%')
            order by PRM_REQUISITION_ID asc
        ";
		$result = $this->db->query($sql);
		$Udata = $result->result_array();
		$Rdata = $result->num_rows();
		if ($Rdata > 0)
		{
			return $Udata;
		}
		else
		{
			return FALSE;
		}
	}
    function getSearchSer($Name)
	{ 
		//$sql = "SELECT b.ID, b.NAME FROM LOGINS a, HRS b WHERE NOT b.NAME = 'Administrator' AND a.hr_id = b.id AND LOWER(b.NAME) LIKE LOWER('%".$Name."%')";
        
        $sql = "
            select distinct(traffic_serial) as ID
            from fm_traffic
            where traffic_serial is not null
                and LOWER(traffic_serial) LIKE LOWER('%".$Name."%')
            order by traffic_serial asc
        ";
		$result = $this->db->query($sql);
		$Udata = $result->result_array();
		$Rdata = $result->num_rows();
		if ($Rdata > 0)
		{
			return $Udata;
		}
		else
		{
			return FALSE;
		}
	}
    function getSearchRel($Name)
	{ 
		//$sql = "SELECT b.ID, b.NAME FROM LOGINS a, HRS b WHERE NOT b.NAME = 'Administrator' AND a.hr_id = b.id AND LOWER(b.NAME) LIKE LOWER('%".$Name."%')";
        
        $sql = "
            select req_url, type, request_no as ID, requestor 
            from v_related_to  
            where LOWER(request_no) LIKE LOWER('%".$Name."%')
            order by type asc, request_no asc
        ";
		$result = $this->db->query($sql);
		$Udata = $result->result_array();
		$Rdata = $result->num_rows();
		if ($Rdata > 0)
		{
			return $Udata;
		}
		else
		{
			return FALSE;
		}
	}
	
	function getSearchVen($Name)
	{ 
		//$sql = "SELECT b.ID, b.NAME FROM LOGINS a, HRS b WHERE NOT b.NAME = 'Administrator' AND a.hr_id = b.id AND LOWER(b.NAME) LIKE LOWER('%".$Name."%')";
        
        $sql = "
        select vendor_id as ID, vendor_name as NAME, PIC 
        from lkk_vendor_mst  
        where LOWER(vendor_name) LIKE LOWER('%".$Name."%')
        order by vendor_name asc
        ";
		$result = $this->db->query($sql);
		$Udata = $result->result_array();
		$Rdata = $result->num_rows();
		if ($Rdata > 0)
		{
			return $Udata;
		}
		else
		{
			return FALSE;
		}
	}
    function getDetailRel($Relid)
	{
        $sql	= "	
            select req_url, type, request_no, requestor 
            from v_related_to  
            where request_no='$Relid'
            "
        ;            
		$result = $this->db->query($sql);
		$Udata 	= $result->row_array();
		$Rdata 	= $result->num_rows();
		if ($Rdata > 0)
		{
			return $Udata;
		}
		else
		{
			return FALSE;
		}
	}
    function getDetailVen($Venid)
	{
		/*$sql	= "	SELECT B.HR_ID, C.NAME, C.ORG, C.JOB_POSITION, (SELECT DISTINCT(NAME) NAME FROM HRS WHERE ID = C.MANAGER) MANAGER, C.EMPLOYEE_TYPE
					FROM LOGINS B, HRS C 
					WHERE NOT C.NAME = 'Administrator' AND B.HR_ID = C.ID AND C.ID = ".$Nik; */
        $sql	= "	
            select vendor_id, vendor_name, PIC 
            from lkk_vendor_mst  
            where vendor_id = '$Venid'"
        ;            
		$result = $this->db->query($sql);
		$Udata 	= $result->row_array();
		$Rdata 	= $result->num_rows();
		if ($Rdata > 0)
		{
			return $Udata;
		}
		else
		{
			return FALSE;
		}
	}
    
	function list_global($arr, $globalvar, $limit = NULL)
	{
        $whereCond = "";
        
        if (!empty($arr)) {
            if (!empty($arr['search_by_option']) && !empty($arr['search_by_keyword'])) {
                if($arr['search_by_option']=='requestor'){
                    $whereCond .= " and requestor in (select id from hrs where upper(name) like upper('%" . $arr['search_by_keyword'] . "%'))";
                }
                else{
                    $whereCond .= "and upper(".$arr['search_by_option'].") like upper('%" . $arr['search_by_keyword'] . "')";
                }
                //$whereCond .= " and upper(regional_name) like upper('%" . $arr['search_by_regional'] . "%')";
            }
            /*if (!empty($arr['search_by_keyword'])) {
                $whereCond .= " and upper(area_status) =upper('" . $arr['search_by_status'] . "')";
                
            }
            if (!empty($arr['search_by_type'])) {
                $whereCond .= " and upper(isdomestic) =upper('" . $arr['search_by_type'] . "')";
            }*/
        }
        //echo $whereCond;
		$sql 	= "
            SELECT b.name requestorname,
                    a.recnum, a.req_closing, a.sdate, a.request_url, a.atasan_nik, a.req_url, a.print_dokumen, a.request_url_ga, 
                        a.type, a.request_no, a.requestor, a.request_for, a.description, a.sdate1, a.atasan_app, a.ga_app, a.it_app, a.ga_followup
            FROM(
                    SELECT recnum, req_closing, sdate, request_url, atasan_nik, req_url, print_dokumen, request_url_ga, 
                            type, request_no, requestor, request_for, description, sdate1, atasan_app, ga_app, it_app, ga_followup 
                    FROM (
                            SELECT req_closing, sdate, request_url, atasan_nik, req_url, print_dokumen, request_url_ga, 
                                    type, request_no, requestor, request_for, description, sdate1, atasan_app, ga_app, it_app, ga_followup, rownum recnum 
                            FROM (
                                    SELECT req_closing, sdate, request_url, atasan_nik, req_url, print_dokumen, request_url_ga, 
                                            type, request_no, requestor, request_for, description, to_char(sdate,'dd/mm/yyYy') sdate1, atasan_app, ga_app, it_app, ga_followup 
                                    FROM v_list_approval 
                                    WHERE atasan_nik is not null 
                                        AND upper(type) in ($globalvar)
                                         ".//AND atasan_app IS NULL
                                         "$whereCond
                                    ORDER BY type asc, request_no desc 
                            )
                    )
                    $limit
            ) A
            LEFT JOIN hrs B
            ON a.requestor=b.id
            ORDER BY a.recnum ASC
        ";
        //echo $sql;
		$query = $this->db->query($sql);
        return $query->result_array();
	}
    /*
    function search_saranaKerja($arr, $globalvar, $limit = NULL)
	{
        $whereCond = "";
        if (!empty($arr)) {
            if (!empty($arr['search_by_regional'])) {
                $whereCond .= " and upper(regional_name) like upper('%" . $arr['search_by_regional'] . "%')";
            }
            if (!empty($arr['search_by_status'])) {
                $whereCond .= " and upper(area_status) =upper('" . $arr['search_by_status'] . "')";
            }
            if (!empty($arr['search_by_type'])) {
                $whereCond .= " and upper(isdomestic) =upper('" . $arr['search_by_type'] . "')";
            }
        }
		$sql 	= "
            SELECT b.name requestorname,
                    a.recnum, a.req_closing, a.sdate, a.request_url, a.atasan_nik, a.req_url, a.print_dokumen, a.request_url_ga, 
                        a.type, a.request_no, a.requestor, a.request_for, a.description, a.sdate1, a.atasan_app, a.ga_app, a.it_app, a.ga_followup
            FROM(
                SELECT recnum, req_closing, sdate, request_url, atasan_nik, req_url, print_dokumen, request_url_ga, 
                        type, request_no, requestor, request_for, description, sdate1, atasan_app, ga_app, it_app, ga_followup 
                FROM (
                        SELECT req_closing, sdate, request_url, atasan_nik, req_url, print_dokumen, request_url_ga, 
                                type, request_no, requestor, request_for, description, sdate1, atasan_app, ga_app, it_app, ga_followup, rownum recnum 
                        FROM (
                                SELECT req_closing, sdate, request_url, atasan_nik, req_url, print_dokumen, request_url_ga, 
                                        type, request_no, requestor, request_for, description, to_char(sdate,'dd/mm/yyYy') sdate1, atasan_app, ga_app, it_app, ga_followup 
                                FROM v_list_approval 
                                WHERE atasan_nik is not null 
                                    AND upper(type) in ($globalvar)
                                    AND a.atasan_app is null
                                     $whereCond
                                ORDER BY type asc, request_no desc 
                        )
                )
                $limit
            ) A
            LEFT JOIN hrs B
            ON a.requestor=b.id
        ";
		$query = $this->db->query($sql);
        //var_dump($query->result_array()); 
        return $query->result_array();
	}
    */
    function count_global($arr, $globalvar)
	{
        //var_dump($arr); 
        //exit;
        $whereCond = "";
        if (!empty($arr)) {
            if (!empty($arr['search_by_option']) && !empty($arr['search_by_keyword'])) {
                if($arr['search_by_option']=='requestor'){
                    $whereCond .= " and requestor in (select id from hrs where upper(name) like upper('%" . $arr['search_by_keyword'] . "%'))";
                }
                else{
                    $whereCond .= "and upper(".$arr['search_by_option'].") like upper('%" . $arr['search_by_keyword'] . "')";
                }
                //$whereCond .= " and upper(regional_name) like upper('%" . $arr['search_by_regional'] . "%')";
            }
            /*if (!empty($arr['search_by_keyword'])) {
                $whereCond .= " and upper(area_status) =upper('" . $arr['search_by_status'] . "')";
                
            }
            if (!empty($arr['search_by_type'])) {
                $whereCond .= " and upper(isdomestic) =upper('" . $arr['search_by_type'] . "')";
            }*/
        }
        //echo $whereCond;
		$sql 	= "
            SELECT COUNT (*) cnt
            FROM(
                SELECT req_closing, sdate, request_url, atasan_nik, req_url, print_dokumen, request_url_ga, 
                        type, request_no, requestor, request_for, description, sdate1, atasan_app, ga_app, it_app, ga_followup 
                FROM (
                        SELECT req_closing, sdate, request_url, atasan_nik, req_url, print_dokumen, request_url_ga, 
                                type, request_no, requestor, request_for, description, sdate1, atasan_app, ga_app, it_app, ga_followup, rownum row_no 
                        FROM (
                                SELECT req_closing, sdate, request_url, atasan_nik, req_url, print_dokumen, request_url_ga, 
                                        type, request_no, requestor, request_for, description, to_char(sdate,'dd/mm/yyYy') sdate1, atasan_app, ga_app, it_app, ga_followup 
                                FROM v_list_approval 
                                WHERE atasan_nik is not null 
                                    AND upper(type) in ($globalvar)
                                    ".//AND atasan_app is null
                                    "$whereCond
                                ORDER BY type asc, request_no desc 
                        )
                )
            )
            
        ";
		$result = $this->db->query($sql)->row();
        //var_dump($result->CNT);
        //exit;
        return $result->CNT;
	}
    
    function getDetail($pCtrlID){
        $sql 	= "SELECT control.USRUPD,
						   hr.NAME,
						   hr.ORG,
						   hr.JOB_POSITION,
						   (SELECT count(*)
							FROM FM_CONTROL_CARD card
							WHERE card.ctrl_id = control.ctrl_id) iscard,
						   (SELECT count(*)
							FROM FM_CONTROL_TELP telp
							WHERE telp.ctrl_id = control.ctrl_id) istelp,
						   CASE WHEN (SELECT card.ctrl_card_user_type FROM FM_CONTROL_CARD card WHERE card.ctrl_id = control.ctrl_id) is null then 
									 (SELECT telp.ctrl_telp_user_type FROM FM_CONTROL_TELP telp WHERE telp.ctrl_id = control.ctrl_id) else
									 (SELECT card.ctrl_card_user_type FROM FM_CONTROL_CARD card WHERE card.ctrl_id = control.ctrl_id) end as use_for,
						   CASE WHEN (SELECT card.ctrl_card_vendor FROM FM_CONTROL_CARD card WHERE card.ctrl_id = control.ctrl_id) is null then 
									 (SELECT telp.ctrl_telp_vendor FROM FM_CONTROL_TELP telp WHERE telp.ctrl_id = control.ctrl_id) else
									 (SELECT card.ctrl_card_vendor FROM FM_CONTROL_CARD card WHERE card.ctrl_id = control.ctrl_id) end as vendor,
						   CASE WHEN (SELECT card.ctrl_card_user FROM FM_CONTROL_CARD card WHERE card.ctrl_id = control.ctrl_id) is null then 
									 (SELECT telp.ctrl_telp_user FROM FM_CONTROL_TELP telp WHERE telp.ctrl_id = control.ctrl_id) else
									 (SELECT card.ctrl_card_user FROM FM_CONTROL_CARD card WHERE card.ctrl_id = control.ctrl_id) end as user_name,
						   to_char(control.DTMUPD,'dd/mm/yyyy') as DTMUPD,
						   control.CTRL_DESCRIPTION,
						   to_char(control.CTRL_DATE_AWAL,'dd/mm/yyyy') as CTRL_DATE_AWAL,
						   to_char(control.CTRL_DATE_AKHIR,'dd/mm/yyyy') as CTRL_DATE_AKHIR,
						   control.CTRL_HOUR_AWAL,
						   control.CTRL_HOUR_AKHIR,
						   control.CTRL_TELP_FISIK,
						   control.CTRL_CARD_FISIK
					FROM FM_ACCESS_CONTROL control INNER JOIN hrs hr
												   ON hr.ID = control.USRUPD
					WHERE control.CTRL_ID = '$pCtrlID'";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function getFloor($pCtrlID){
        $sql 	= "  SELECT cardflor.CARD_FLOOR_NAME
			         FROM fm_access_control acces 
                     INNER JOIN fm_control_card cardcon
			             ON acces.CTRL_ID = cardcon.CTRL_ID
			         INNER JOIN CONTROL_CARD_FLOOR cardflor
			             ON cardcon.CTRL_CARD_ID = cardflor.CRTL_CARD_ID
			         WHERE acces.CTRL_ID = '$pCtrlID' 
                     ORDER BY cardflor.CARD_FLOOR_NAME";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function getFloor2($pCtrlID){
        $sql 	= "  SELECT telpext.TELP_EXT_EXT_TYPE
			         FROM fm_access_control acces 
                     INNER JOIN fm_control_telp telpcon
			             ON acces.CTRL_ID = telpcon.CTRL_ID
			         INNER JOIN CONTROL_TELP_EXT telpext
			             ON telpcon.CTRL_TELP_ID = telpext.CRTL_TELP_ID
			         WHERE acces.CTRL_ID = '$pCtrlID'";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function appMgrSrnKrjRmDetail($pCtrlID){
        $sql 	= "  SELECT rm.rm_atasan_id,rm.rm_id, rm.rm_date, 
			   rm.rm_type, rm.rm_category, 
			   rm.rm_vendor, rm.rm_atasan_app, 
			   rm.rm_ga_app, rm.rm_floor,
			   rm.RM_DESCRIPTION,
			   rm.RM_SERIAL,
			   rm.RM_SUITE,
			   rm.rm_nip,
			   to_char(rm.RM_RETURN,'DD/MM/YYYY') as RM_RETURN,
			   to_char(rm.RM_DELIVERY,'DD/MM/YYYY') as RM_DELIVERY,
			   hr.id,
			   hr.NAME,
			   hr.ORG,
			   hr.JOB_POSITION,
			   (select hr.id from hrs hr where hr.id = rm.rm_untuk_nik) as id1,
			   (select hr.name from hrs hr where hr.id = rm.rm_untuk_nik) as name1,
			   (select hr.org from hrs hr where hr.id = rm.rm_untuk_nik) as org1,
			   (select hr.job_position from hrs hr where hr.id = rm.rm_untuk_nik) as job1
		FROM fm_rm rm inner join hrs hr
					  on rm.RM_ATASAN_ID = hr.id
		WHERE rm.rm_id = '$pCtrlID'";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    /*
    function allEditSave($data,$id,$getDbName,$getPrimColumnName){
        var_dump($data);
        var_dump($id);
        var_dump($getDbName);
        var_dump($getPrimColumnName);
        
        $sql 	= "  UPDATE
			         SET
			         WHERE CTRL_ID = '$pCtrlID'";
        $query = $this->db->query($sql);
        $this->db->where($getPrimColumnName,$id);  
        $this->db->update($getDbName,$data);	
	}*/
    function appManagerSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['$Comment'];
        //$pAccesNo=$arr['$pAccesNo'];
        
        //echo $pCtrlID;
        //var_dump($arr);
        //exit;
        
        $sql 	= "  UPDATE FM_ACCESS_CONTROL
			         SET CTRL_ATASAN_APP='$pApproval',CTRL_COMMENT_ATASAN='$pComment',CTRL_ATASAN_APP_DATE=sysdate
			         WHERE CTRL_ID = '$pCtrlID'";
        //echo $sql; exit;             
        $query = $this->db->query($sql);
        
        //$this->db->where($getPrimColumnName,$id);  
        //$this->db->update($getDbName,$data);
        	
	}
    
    function appMgrSrnKrjReqSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        
        $sql 	= "update fm_req_head set req_atasan_app='$pApproval', req_atasan_app_date=sysdate where req_id='$pCtrlID'";
        //echo $sql; //exit;
        $query = $this->db->query($sql);
	}
    function appMgrSrnKrjRmSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        
        $sql 	= "update FM_RM set RM_ATASAN_APP='$pApproval', RM_COMMENT_ATASAN= '$pComment', RM_ATASAN_APP_DATE=sysdate where RM_ID='$pCtrlID'";
        //echo $sql; //exit;
        $query = $this->db->query($sql);
	}
    function appMgrSrnKrjSikSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        
        $sql 	= "update fm_sik set sik_atasan_app='$pApproval', sik_atasan_app_date=sysdate where sik_id='$pCtrlID'";
        //echo $sql; exit;
        $query = $this->db->query($sql);
	}
    function appMgrSrnKrjOvtSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        
        $sql 	= "update fm_so set so_atasan_app='$pApproval', so_atasan_app_date=sysdate where so_id='$pCtrlID'";
        //echo $sql; exit;
        $query = $this->db->query($sql);
	}
    function appMgrSrnKrjPrkSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        
        $sql 	= "update fm_parkir_det set parkird_atasan_app='$pApproval', parkird_atasan_app_date=sysdate where parkird_id='$pCtrlID'";
        //echo $sql; exit;
        $query = $this->db->query($sql);
	}
    function appMgrServPagSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        
        $sql 	= "update fm_paging_info set info_atasan_app='$pApproval', info_atasan_app_date=sysdate where info_id='$pCtrlID'";
        //echo $sql; exit;
        $query = $this->db->query($sql);
	}
    function appGaSrnKrjReqSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        $pBudget=$arr['pBudget'];
        $nik=$arr['sesNik'];
        
        $sql 	= "update fm_req_head set req_ga_app='$pApproval', req_ga_app_date=sysdate, req_ga_nik='$nik', REQ_BUDGET_GA = '$pBudget' where req_id='$pCtrlID'";
        //echo $sql; exit;
        $query = $this->db->query($sql);
	}
    function appGaSrnKrjRmSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        //$pBudget=$arr['pBudget'];
        $nik=$arr['sesNik'];
        
        $sql 	= "update FM_RM set RM_GA_APP='$pApproval', 
		                               RM_GA_APP_DATE=sysdate, 
									   RM_GA_ID = '$nik',
									   RM_COMMENT_GA = '$pComment'
					where RM_ID='$pCtrlID'";
        //echo $sql; exit;
        $query = $this->db->query($sql);
	}
    function appGaSrnKrjSikSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        //$pBudget=$arr['pBudget'];
        $nik=$arr['sesNik'];
        
        $sql 	= "update fm_sik set sik_ga_app='$pApproval', sik_ga_app_date=sysdate, sik_ga_nik='$nik', sik_ga_comment='$pComment' where sik_id='$pCtrlID'";
        //echo $sql; exit;
        $query = $this->db->query($sql);
	}
    function appGaSrnKrjOvtSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        //$pBudget=$arr['pBudget'];
        $nik=$arr['sesNik'];
        
        $sql 	= "update fm_so set so_ga_app='$pApproval', so_ga_app_date=sysdate, so_ga_nik='$nik', so_comment='$pComment' where so_id='$pCtrlID'";
        //echo $sql; exit;
        $query = $this->db->query($sql);
	}
    function appGaSrnKrjPrkSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        //$pBudget=$arr['pBudget'];
        $nik=$arr['sesNik'];
        
        $sql 	= "update fm_parkir_det set parkird_ga_nik = '$nik', parkird_ga_app='$pApproval', parkird_ga_app_date=sysdate, parkird_comment='$pComment' where parkird_id='$pCtrlID'";
        //echo $sql; exit;
        $query = $this->db->query($sql);
	}
    function appGaPubRomMeetSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        //$pBudget=$arr['pBudget'];
        $nik=$arr['sesNik'];
        
        $sql 	= "update FM_MEETING_ROOM set ROOM_GA_APP = '$pApproval', ROOM_COMMENT_GA = '$pComment', ROOM_GA_APP_DATE = sysdate, ROOM_GA_ID = '$nik' where ROOM_ID = '$pCtrlID'";
        echo $sql; //exit;
        $query = $this->db->query($sql);
	}
    function appGaPubRomMeetSelect1($pCtrlID){
        $sql 	= "select det.ROOMD_QTY,
                        det.warehouse_id
                   from FM_MEETING_ROOM_DET det 
                   where det.room_id = '$pCtrlID'";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function appGaPubRomMeetSelect2($pCtrlID,$pWareItemId){
        $sql 	= "select det.ROOMD_QTY
                   from FM_MEETING_ROOM_DET det
                   where det.WAREHOUSE_ID = '$pWareItemId'
                        and det.room_id = '$pCtrlID'";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function appGaPubRomMeetUpdate1($pQty,$pWareItemId){
        $sql 	= "update FM_WAREHOUSE 
                   set WAREHOUSE_ITEM_QTY_IN = (WAREHOUSE_ITEM_QTY_IN - $pQty),
                        WAREHOUSE_ITEM_QTY_OUT = (WAREHOUSE_ITEM_QTY_OUT + $pQty)
                   where WAREHOUSE_ID = '$pWareItemId'";
        echo $sql; //exit;
        $query = $this->db->query($sql);          
    }
    function appGaPubRomMeetUpdate2($pCtrlID,$pWareItemId){
        $sql 	= "update FM_MEETING_ROOM_DET det set det.ROOMD_STATUS = 'N'
                   where det.WAREHOUSE_ID = '$pWareItemId'
                   and det.room_id = '$pCtrlID'";
        echo $sql; //exit;
        $query = $this->db->query($sql);          
    }
    function appGaPubRomMeetDelete1($pCtrlID){
        $sql 	= "delete from FM_MEETING_ROOM_DET_PR where ROOM_ID = '$pCtrlID'";
        echo $sql; //exit;
        $query = $this->db->query($sql);          
    }
    function appGaPubRomMeetDelete2($pCtrlID){
        $sql 	= "delete from FM_MEETING_ROOM_DET where ROOM_ID = '$pCtrlID'";
        echo $sql; //exit;
        $query = $this->db->query($sql);          
    }
    function appGaPubRomMeetDelete3($pCtrlID){
        $sql 	= "delete from FM_MEETING_ROOM where ROOM_ID = '$pCtrlID'";
        echo $sql; //exit;
        $query = $this->db->query($sql);          
    }
    function appGaServPagSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        //$pBudget=$arr['pBudget'];
        $nik=$arr['sesNik'];
        
        $sql 	= "update fm_paging_info set info_ga_app='$pApproval', info_ga_app_date=sysdate, info_ga_nik='$nik', info_ga_comment='$pComment' where info_id='$pCtrlID'";
        echo $sql; //exit;
        $query = $this->db->query($sql);
	}
    //tambahan sendiri berdasarkan pApproval, jika Follow Up nya kosong
    function appGaServSarKelSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        $pFollowUp=$arr['pFollowUp'];
        $nik=$arr['sesNik'];
        
        $sql 	= "update fm_pobox set pobox_ga_nik='$nik', pobox_ga_app='$pApproval', pobox_ga_app_date=sysdate, pobox_ga_app_follow='$pFollowUp' where pobox_id='$pCtrlID'";
        echo $sql; //exit;
        $query = $this->db->query($sql);
	}
    //End
    function appGaServSarKelSaveY($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        $pFollowUp=$arr['pFollowUp'];
        $nik=$arr['sesNik'];
        
        $sql 	= "update fm_pobox set pobox_ga_nik='$nik', pobox_ga_app='Y', pobox_ga_app_date=sysdate, pobox_ga_app_follow='$pFollowUp' where pobox_id='$pCtrlID'";
        echo $sql; //exit;
        $query = $this->db->query($sql);
	}
    function getDetailPublicRoom($pDmrID){
        $sql 	= "select hr.id,
				       hr.NAME,
				       hr.ORG,
				       hr.JOB_POSITION,
				       dmr.DMR_COURIER_TYPE,
				       (select area.area_name||' - '||area.regional_name
				        from FM_MST_AREA area
				        where area.area_name = dmr.DMR_TUJUAN
						AND area.REGIONAL_NAME = dmr.DMR_REGIONAL) DMR_TUJUAN,
				       dmr.DMR_PENJEMPUTAN,
				       dmr.DMR_FLOOR,
				       dmr.DMR_TYPE,
				       dmr.DMR_CATEGORY,
				       dmr.DMR_WAKTU_PENJEMPUTAN,
				       dmr.DMR_DESCRIPTION
			   from FM_DMR dmr inner join hrs hr
				                on dmr.DMR_ATASAN_APP_ID = hr.ID 
			   where dmr.DMR_ID = '$pDmrID'";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function appManagerPublicRoomSave($arr){
        $pDmrID=$arr['pDmrID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        $sql 	= "UPDATE FM_DMR 
                    SET DMR_ATASAN_APP='$pApproval', DMR_COMMENT_ATASAN = '$pComment', DMR_ATASAN_APP_DATE=sysdate 
                    WHERE DMR_ID='$pDmrID'";            
        $query = $this->db->query($sql);
	}
    function getDetailPagingInfo($pCtrlID){
        $sql 	= "
            select info_shour, info_sminute, info_repetition, 
                info_keterangan, info_untuk_nik, info_atasan_nik, 
                info_id, info_nik, to_char(info_sdate,'dd/mm/yyyy') info_sdate, 
                info_subject, info_description 
            from fm_paging_info 
            where info_id='$pCtrlID'            
        ";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function getDetailGa($pCtrlID){
        $sql 	= "
                    SELECT hr2.name as nama_atasan,
                            control.USRUPD,
						   hr.NAME,
						   hr.ORG,
						   hr.JOB_POSITION,
						   (SELECT count(*)
							FROM FM_CONTROL_CARD card
							WHERE card.ctrl_id = control.ctrl_id) iscard,
						   (SELECT count(*)
							FROM FM_CONTROL_TELP telp
							WHERE telp.ctrl_id = control.ctrl_id) istelp,
						   CASE WHEN (SELECT card.ctrl_card_user_type FROM FM_CONTROL_CARD card WHERE card.ctrl_id = control.ctrl_id) is null then 
									 (SELECT telp.ctrl_telp_user_type FROM FM_CONTROL_TELP telp WHERE telp.ctrl_id = control.ctrl_id) ELSE
									 (SELECT card.ctrl_card_user_type FROM FM_CONTROL_CARD card WHERE card.ctrl_id = control.ctrl_id) end as use_for,
						   CASE WHEN (SELECT card.ctrl_card_vendor FROM FM_CONTROL_CARD card WHERE card.ctrl_id = control.ctrl_id) is null then 
									 (SELECT telp.ctrl_telp_vendor FROM FM_CONTROL_TELP telp WHERE telp.ctrl_id = control.ctrl_id) ELSE
									 (SELECT card.ctrl_card_vendor FROM FM_CONTROL_CARD card WHERE card.ctrl_id = control.ctrl_id) end as vendor,
						   CASE WHEN (SELECT card.ctrl_card_user FROM FM_CONTROL_CARD card WHERE card.ctrl_id = control.ctrl_id) is null then 
									 (SELECT telp.ctrl_telp_user FROM FM_CONTROL_TELP telp WHERE telp.ctrl_id = control.ctrl_id) ELSE
									 (SELECT card.ctrl_card_user FROM FM_CONTROL_CARD card WHERE card.ctrl_id = control.ctrl_id) end as user_name,
						   to_char(control.DTMUPD,'dd/mm/yyyy') as DTMUPD,
						   control.CTRL_DESCRIPTION,
						   to_char(control.CTRL_DATE_AWAL,'dd/mm/yyyy') as CTRL_DATE_AWAL,
						   to_char(control.CTRL_DATE_AKHIR,'dd/mm/yyyy') as CTRL_DATE_AKHIR,
						   control.CTRL_HOUR_AWAL,
						   control.CTRL_HOUR_AKHIR,
						   control.ctrl_atasan_id,
						   control.CTRL_TELP_FISIK,
						   control.CTRL_CARD_FISIK,
						   control.ctrl_file,
						   control.ctrl_filename
					FROM FM_ACCESS_CONTROL control 
                    INNER JOIN hrs hr
                        ON hr.ID = control.USRUPD
                    LEFT JOIN hrs hr2
                        ON hr2.ID=control.CTRL_ATASAN_ID   
					WHERE control.CTRL_ID = '$pCtrlID'
        ";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function getFloorGa($pCtrlID){
        //QUERY ORI, DIUBAH KARENA MENYAMAKAN DENGAN PADA SAAT MENU EDIT DITEKAN
        /*$sql 	= "  SELECT cardflor.CARD_FLOOR_NAME
        			 FROM fm_access_control acces 
                     INNER JOIN fm_control_card cardcon
			             ON acces.CTRL_ID = cardcon.CTRL_ID
			         INNER JOIN CONTROL_CARD_FLOOR cardflor
			             ON cardcon.CTRL_CARD_ID = cardflor.CRTL_CARD_ID
        			 WHERE acces.CTRL_ID = '$pCtrlID' order by cardflor.CARD_FLOOR_NAME";
        */             
        $sql 	= "  SELECT distinct cardflor.CARD_FLOOR_NAME
        			 FROM fm_access_control acces 
                     INNER JOIN fm_control_card cardcon
			             ON acces.CTRL_ID = cardcon.CTRL_ID
			         INNER JOIN CONTROL_CARD_FLOOR cardflor
			             ON cardcon.CTRL_CARD_ID = cardflor.CRTL_CARD_ID
        			 WHERE acces.CTRL_ID = '$pCtrlID' order by cardflor.CARD_FLOOR_NAME";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function getFloor2Ga($pCtrlID){
        $sql 	= " SELECT telpext.TELP_EXT_EXT_TYPE
        			FROM fm_access_control acces INNER JOIN fm_control_telp telpcon
                        ON acces.CTRL_ID = telpcon.CTRL_ID
                    INNER JOIN CONTROL_TELP_EXT telpext
                        ON telpcon.CTRL_TELP_ID = telpext.CRTL_TELP_ID
        			WHERE acces.CTRL_ID = '$pCtrlID'";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function appGaSave($arr){
        $pCtrlID=$arr['pCtrlID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        $nik="";
        
        //original QUERY --> terdapat $nik yang didapat dari lib inc, sepertinya userlogin
        //sementara didisabel dulu, masukkan nilainya jika login sudah selesai
        //$sql 	= "UPDATE FM_ACCESS_CONTROL 
        //            SET CTRL_GA_APP = '$pApproval', CTRL_COMMENT_GA = '$pComment', CTRL_GA_APP_DATE = sysdate, CTRL_GA_ID = '$nik' 
        //            WHERE CTRL_ID = '$pCtrlID'";
        $sql 	= "UPDATE FM_ACCESS_CONTROL 
                    SET CTRL_GA_APP = '$pApproval', CTRL_COMMENT_GA = '$pComment', CTRL_GA_APP_DATE = sysdate, CTRL_GA_ID = '$nik' 
                    WHERE CTRL_ID = '$pCtrlID'";            
        $query = $this->db->query($sql);
	}
    
    function getDetailPublicRoomGa($pDmrID){
        $sql 	= "SELECT hr.id,
				       hr.NAME,
				       hr.ORG,
				       hr.JOB_POSITION,
				       dmr.DMR_COURIER_TYPE,
				       (SELECT area.area_name||' - '||area.regional_name
				        FROM FM_MST_AREA area
				        WHERE area.area_name = dmr.DMR_TUJUAN and area.regional_name=dmr.dmr_regional) DMR_TUJUAN,
				       dmr.DMR_PENJEMPUTAN,
				       dmr.DMR_FLOOR,
				       dmr.DMR_TYPE,
				       dmr.DMR_CATEGORY,
				       dmr.DMR_WAKTU_PENJEMPUTAN,
				       dmr.DMR_DESCRIPTION,
					   dmr.DMR_ATASAN_APP_ID,
					   to_char(dmr.DMR_RECIEVE_DATE,'DD/MM/YYYY') as DMR_RECIEVE_DATE
			   FROM FM_DMR dmr 
               INNER JOIN hrs hr
	               ON dmr.DMR_ATASAN_APP_ID = hr.ID 
			   WHERE dmr.DMR_ID = '$pDmrID'";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function getKurirPublicRoomGa($vcouriertype){
        $sql 	= "SELECT "." DISTINCT ".
                    " curir.COURIER_ID,
				    curir.COURIER_NAME
				    FROM FM_MST_COURIER_MAPPING mapping 
                    INNER JOIN FM_MST_COURIER curir
						ON mapping.COURIER_ID = curir.COURIER_ID
				    WHERE curir.COURIER_STATUS = 'Y'
				    AND mapping.ID_COURIER_TYPE = '$vcouriertype'
        ";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function getKurir2PublicRoomGa($vRecieveDate){
        $sql 	= "SELECT mst.MESSENGER_ID as COURIER_ID, mst.MESSENGER_NAME as COURIER_NAME
    				 FROM FM_TRANS_MESSENGER trans 
                     INNER JOIN FM_MST_MESSENGER mst
                        ON trans.TRANS_MESSENGER_ID = mst.MESSENGER_ID
    				 WHERE trunc(trans.TRANS_DATE) = to_date('$vRecieveDate','DD/MM/YYYY')
    				    AND trans.TRANS_APP = 'Y'
    				    AND trans.TRANS_STATUS = 'Out'
        ";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function getDetailMeetingRoomGa($pRoomId){
        $sql 	= "select room.ROOM_FLOOR,
			       room.ROOM_JENIS,
			       room.ROOM_TYPE,
			       to_char(room.ROOM_DATE,'dd/MM/yyyy') as ROOM_DATE,
			       room.ROOM_SHOUR||':'||room.ROOM_SMINUTE as Star_hour,
			       room.ROOM_EHOUR||':'||room.ROOM_EMINUTE as End_hour,
			       room.ROOM_DESCRIPTION,
			       room.ROOM_PARTICIPANT,
			       room.ROOM_CONDITION,
			       hr.ID,
			       hr.NAME,
			       hr.ORG,
			       hr.JOB_POSITION
			from fm_meeting_room room left join hrs hr
			                          on room.ROOM_UNTUK_NIK = hr.ID
			where room.room_id = '$pRoomId'";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function getDetailMeetingRoomGa2($pRoomId){
        $sql 	= "select det.roomd_description,
				  det.roomd_qty,
				  (select nvl(house.WAREHOUSE_ITEM_QTY_IN,0)
				   from FM_WAREHOUSE house
				   where det.WAREHOUSE_ID = house.WAREHOUSE_ID) as WAREHOUSE_ITEM_QTY_IN,
				  det.ROOMD_ID,
                  det.WAREHOUSE_ID
		   from FM_MEETING_ROOM_DET det
		   where det.room_id = '$pRoomId'
		   and det.ROOMD_STATUS = 'Y'";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    function appGaPublicRoomSave($arr){
        $pDmrID=$arr['pDmrID'];
        $pApproval=$arr['pApproval'];
        $pComment=$arr['pComment'];
        $pDmKurir=$arr['pDmKurir'];
        $pDmBerat=$arr['pDmBerat'];
        $nik="";
        
        //Sementara acuhkan $nik-> karena mengambil dari userlogin, sedang dibuatkan sessionnya
        $sql 	= "
                UPDATE FM_DMR 
                SET DMR_GA_APP='$pApproval', 
                    DMR_GA_APP_DATE=sysdate, 
	                DMR_GA_APP_ID = '$nik',
	                COURIER_ID = '$pDmKurir',
	                DMR_BERAT = '$pDmBerat',
	                DMR_COMMENT_GA = '$pComment'
				WHERE DMR_ID='$pDmrID'
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
	}
    
    function getDetailServicesGa($pOrderID){
        $sql 	= "SELECT head.ORDER_ID,
    					head.ORDER_DESCRIPTION,
    					head.ORDER_FOR,
    					head.HR_ID,
    					head.ORDER_STATUS,
    					to_char(head.ORDER_TGL_AWAL,'DD/MM/YYYY') as ORDER_TGL_AWAL,
    					to_char(head.ORDER_TGL_AKHIR,'DD/MM/YYYY') as ORDER_TGL_AKHIR,
    					to_char(head.ORDER_DATE,'DD/MM/YYYY') as ORDER_DATE,
    					hr.ID,
    					hr.NAME,
    					hr.ORG,
    					hr.JOB_POSITION,  
                        hr2.ORG as orgbyhrid ,
                        hr2.JOB_POSITION as jobbyhrid,
                        hr2.NAME as namebyhrid  
			         FROM FM_ORDER_HEADER head 
                     LEFT JOIN HRS hr
                        ON head.ORDER_FOR = hr.ID
                     LEFT JOIN HRS hr2
                        ON head.HR_ID=hr2.ID
			         WHERE head.ORDER_ID = '$pOrderID'";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    
    function getDetail2ServicesGa($pOrderID){
        $sql 	= "SELECT det.warehouse_name,
				        det.order_det_qty,
				        (
                            SELECT nvl(house.WAREHOUSE_ITEM_QTY_IN,0)
                            FROM FM_WAREHOUSE house
				            WHERE det.WAREHOUSE_ID = house.WAREHOUSE_ID
                        ) as WAREHOUSE_ITEM_QTY_IN,
				        det.ORDER_DET_ID,
                        det.WAREHOUSE_ID
        		   FROM FM_ORDER_DETAIL det
        		   WHERE det.ORDER_ID = '$pOrderID'
        		   AND det.ORDER_DET_STATUS = 'Y'
                   ";
        $query = $this->db->query($sql);
        return $query->result_array();           
    }
    
    
    
    function appGaServicesSave($arr){
        $pOrderID    	=  $arr['pOrderID'];
        $pApproval    	=  $arr['pApproval'];
        $pComment		=  $arr['pComment'];
        $pWareItemId	=  $arr['pWareItemId'];
        $pCheck		    =  $arr['pCheck'];
        $nik="";
        
        //var_dump($arr); 
        //Sementara acuhkan $nik-> karena mengambil dari userlogin, sedang dibuatkan sessionnya
        $sql 	= "
                UPDATE FM_ORDER_HEADER 
                SET ORDER_GA_APP = '$pApproval', ORDER_GA_COMMENT = '$pComment', ORDER_GA_APP_DATE = sysdate, ORDER_GA_ID = '$nik' 
                WHERE ORDER_ID = '$pOrderID'
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
	}
    
    function appGaServicesSaveN($arr){
        $pOrderID    	=  $arr['pOrderID'];
        $pApproval    	=  $arr['pApproval'];
        $pComment		=  $arr['pComment'];
        $pWareItemId	=  $arr['pWareItemId'];
        $pCheck		    =  $arr['pCheck'];
        $nik="";
        
        //var_dump($arr); 
        //Sementara acuhkan $nik-> karena mengambil dari userlogin, sedang dibuatkan sessionnya
        $sql 	= "
                UPDATE FM_ORDER_DETAIL 
                SET ORDER_DET_STATUS  = 'N' 
                WHERE ORDER_ID = '$pOrderID'
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
	}
    
    function appGaServicesCekBarangPesanan($pOrderID){
        $sql 	= "
                SELECT det.ORDER_DET_QTY,
                        det.WAREHOUSE_ID
                FROM FM_ORDER_DETAIL det 
	            WHERE det.ORDER_ID = '$pOrderID'
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        return $query->result_array();  
	}
    function appGaServicesCekBarangPesananQty($pOrderID,$pWareItemId){
        $sql 	= "
                select det.ORDER_DET_QTY
                from FM_ORDER_DETAIL det
                where det.WAREHOUSE_ID = '$pWareItemId'
                and det.ORDER_ID = '$pOrderID'
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        return $query->result_array();  
	}
    function appGaServicesUpdateJumlahBarangWarehouse($pQty,$pWareItemId){
        //ORI
        /*$sql 	= "
                UPDATE FM_WAREHOUSE 
                SET WAREHOUSE_ITEM_QTY_IN = (WAREHOUSE_ITEM_QTY_IN - $pQty)
                    ,WAREHOUSE_ITEM_QTY_OUT = (WAREHOUSE_ITEM_QTY_OUT + $pQty)
                WHERE WAREHOUSE_ID = '$pWareItemId'
        "; 
        */  
        //EDITANKU All=in+out
        $sql 	= "
                UPDATE FM_WAREHOUSE 
                SET WAREHOUSE_ITEM_QTY_IN = (WAREHOUSE_ITEM_QTY_IN - $pQty)
                    ,WAREHOUSE_ITEM_QTY_OUT = (WAREHOUSE_ITEM_QTY_OUT + $pQty)
                    ,WAREHOUSE_ITEM_QTY = (WAREHOUSE_ITEM_QTY_IN + WAREHOUSE_ITEM_QTY_OUT)
                WHERE WAREHOUSE_ID = '$pWareItemId'
        ";    
        //echo $sql; 
        //exit;        
        $query = $this->db->query($sql);
	}
    function appGaServicesSaveN2($pOrderID,$pWareItemId){
        
        //var_dump($arr); 
        //Sementara acuhkan $nik-> karena mengambil dari userlogin, sedang dibuatkan sessionnya
        $sql 	= "
                UPDATE FM_ORDER_DETAIL det 
                SET det.ORDER_DET_STATUS = 'N'
                WHERE det.WAREHOUSE_ID = '$pWareItemId'
                    AND det.ORDER_ID = '$pOrderID'
        ";    
        //echo $sql; 
        //exit;        
        $query = $this->db->query($sql);
	}
    function appGaServicesCekStockWarehouse($pWareItemId){
        $sql 	= "
                SELECT WAREHOUSE_ID,WAREHOUSE_ITEM_QTY,WAREHOUSE_ITEM_QTY_IN,WAREHOUSE_ITEM_QTY_OUT
                FROM FM_WAREHOUSE
                WHERE WAREHOUSE_ID='$pWareItemId'
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        return $query->result_array();  
	}
    function getDetailCloseSrnKrjAcc($cRequestNo){
        $sql 	= "
                select hr2.NAME as ATASANNAME,
                        hr3.NAME as NIPNAME,
                        hr3.JOB_POSITION as NIPJOBPOSITION,
                        hr3.ORG as NIPORG,
                        control.USRUPD,
				       control.ctrl_nip,
				       hr.NAME,
				       hr.ORG,
				       hr.JOB_POSITION,
				       (select count(*)
				        from FM_CONTROL_CARD card
				        where card.ctrl_id = control.ctrl_id) iscard,
				       (select count(*)
				        from FM_CONTROL_TELP telp
				        where telp.ctrl_id = control.ctrl_id) istelp,
				       case when (select card.ctrl_card_user_type from FM_CONTROL_CARD card where card.ctrl_id = control.ctrl_id) is null then 
				                 (select telp.ctrl_telp_user_type from FM_CONTROL_TELP telp where telp.ctrl_id = control.ctrl_id) else
				                 (select card.ctrl_card_user_type from FM_CONTROL_CARD card where card.ctrl_id = control.ctrl_id) end as use_for,
				       case when (select card.ctrl_card_vendor from FM_CONTROL_CARD card where card.ctrl_id = control.ctrl_id) is null then 
				                 (select telp.ctrl_telp_vendor from FM_CONTROL_TELP telp where telp.ctrl_id = control.ctrl_id) else
				                 (select card.ctrl_card_vendor from FM_CONTROL_CARD card where card.ctrl_id = control.ctrl_id) end as vendor,
				       case when (select card.ctrl_card_user from FM_CONTROL_CARD card where card.ctrl_id = control.ctrl_id) is null then 
				                 (select telp.ctrl_telp_user from FM_CONTROL_TELP telp where telp.ctrl_id = control.ctrl_id) else
				                 (select card.ctrl_card_user from FM_CONTROL_CARD card where card.ctrl_id = control.ctrl_id) end as user_name,
				       to_char(control.DTMUPD,'dd/mm/yyyy') as DTMUPD,
				       control.CTRL_DESCRIPTION,
					   to_char(control.CTRL_DATE_AWAL,'dd/mm/yyyy') as CTRL_DATE_AWAL,
					   to_char(control.CTRL_DATE_AKHIR,'dd/mm/yyyy') as CTRL_DATE_AKHIR,
					   control.CTRL_HOUR_AWAL,
					   control.CTRL_HOUR_AKHIR,
					   control.ctrl_atasan_id
				from FM_ACCESS_CONTROL control 
                inner join hrs hr
                    on hr.ID = control.USRUPD
                    
                LEFT JOIN hrs hr2
                    ON hr2.ID=control.ctrl_atasan_id
                LEFT JOIN hrs hr3
                    ON hr3.ID=control.ctrl_nip                                
				where control.CTRL_ID = '$cRequestNo'
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        return $query->result_array(); 
    }
    function getFloorCloseSrnKrjAcc($cRequestNo){
        $sql 	= "
                select cardflor.CARD_FLOOR_NAME
			from fm_access_control acces inner join fm_control_card cardcon
										 on acces.CTRL_ID = cardcon.CTRL_ID
										 inner join CONTROL_CARD_FLOOR cardflor
										 on cardcon.CTRL_CARD_ID = cardflor.CRTL_CARD_ID
			where acces.CTRL_ID = '$cRequestNo' order by CARD_FLOOR_NAME
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        return $query->result_array(); 
    }
    function getFloor2CloseSrnKrjAcc($cRequestNo){
        $sql 	= "
                select telpext.TELP_EXT_EXT_TYPE
			from fm_access_control acces inner join fm_control_telp telpcon
										 on acces.CTRL_ID = telpcon.CTRL_ID
										 inner join CONTROL_TELP_EXT telpext
										 on telpcon.CTRL_TELP_ID = telpext.CRTL_TELP_ID
			where acces.CTRL_ID = '$cRequestNo'
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        return $query->result_array(); 
    }
    function closeSrnKrjAccSave($arr){
        $pApproval=$arr['pApproval'];
        $pReqClosing=$arr['pReqClosing'];
        //echo $arr; exit;
        $sql 	= "
                update fm_access_control 
                set ctrl_clossing='$pApproval', ctrl_clossing_date=sysdate 
                where ctrl_id='$pReqClosing'
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        
    }
    function getDetailCloseSrnKrjSik($cRequestNo){
        //NOTE : LEFT JOIN HANYA AKAN WORK KALO FROM DI DEPANNYA HANYA 1 TABEL, TIDAK BISA LEBIH
        $sql 	= "
                select hr2.NAME as ATASANNAME,
                       hr3.NAME as NIKNAME,
                       hr3.ORG as NIKORG,
                       hr3.JOB_POSITION as NIKJOBPOSITION,
                       tabelUtama.*
                from(       
                                select 
                                        
                                        a.sik_untuk_nik, a.sik_atasan_nik, a.sik_id, a.sik_nik, to_char(a.sik_sdate,'dd/mm/yyyy') sik_sdate, 
                                        to_char(a.sik_edate,'dd/mm/yyyy') sik_edate, a.vendor_id, a.mst_floor_id, b.vendor_name, a.vendor_pic, 
                                        substr(sik_shour,1,2) shours, substr(sik_shour,4,2) ehours, 
                                        substr(sik_ehour,1,2) shoure, substr(sik_ehour,4,2) ehoure, a.vendor_jabatan 
                                from fm_sik a, lkk_vendor_mst b 
                                where a.vendor_id = b.vendor_id 
                                and a.sik_id='$cRequestNo'
                ) tabelUtama
                LEFT JOIN hrs hr2
                  ON hr2.ID=tabelUtama.sik_atasan_nik
                LEFT JOIN hrs hr3
                  ON hr3.ID=tabelUtama.sik_untuk_nik 
        ";    
        //echo $sql; //exit;        
        $query = $this->db->query($sql);
        return $query->result_array(); 
    }
    function getDetail2CloseSrnKrjSik($cRequestNo){
        $sql 	= "
                select * 
                from fm_sik_job 
                where sik_id='$cRequestNo' 
                order by sikj_id asc
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        return $query->result_array(); 
    }
    function closeSrnKrjSikSave($arr){
        $pApproval=$arr['pApproval'];
        $pReqClosing=$arr['pReqClosing'];
        //echo $arr; exit;
        $sql 	= "
                update fm_sik 
                set sik_closing='$pApproval', sik_closing_date=sysdate 
                where sik_id='$pReqClosing'
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        
    }
    function getDetailCloseSrnKrjReq($cRequestNo){
        //NOTE : LEFT JOIN HANYA AKAN WORK KALO FROM DI DEPANNYA HANYA 1 TABEL, TIDAK BISA LEBIH
        $sql 	= "
                select hr2.NAME as ATASANNAME,
                       hr3.NAME as NIKNAME,
                       hr3.ORG as NIKORG,
                       hr3.JOB_POSITION as NIKJOBPOSITION,
                       tabelUtama.*
                from(
                    select req_info_hrd, req_floor, req_rbf_id, req_id, req_date, req_description, 
                            req_nik, req_untuk_nik, req_atasan_nik 
                    from fm_req_head 
                    where req_id='$cRequestNo'
                ) tabelUtama
                LEFT JOIN hrs hr2
                  ON hr2.ID=tabelUtama.REQ_ATASAN_NIK
                LEFT JOIN hrs hr3
                  ON hr3.ID=tabelUtama.REQ_UNTUK_NIK 
        ";    
        //echo $sql; //exit;        
        $query = $this->db->query($sql);
        return $query->result_array(); 
    }
    function getDetail2CloseSrnKrjReq($cRequestNo){
        $sql 	= "
                select a.parkird_nik, a.parkird_untuk_nik, a.parkird_atasan_nik, a.parkird_type, a.parkird_plat, a.parkird_stnk,
    			   a.parkird_date, a.parkird_description, a.parkird_file, a.parkird_use_by,
    			   a.parkird_type_1, a.parkird_plat_1, a.parkird_stnk_1, a.parkird_flag_1,
    			   a.parkird_type_2, a.parkird_plat_2, a.parkird_stnk_2, a.parkird_flag_2,
    			   a.parkird_type_3, a.parkird_plat_3, a.parkird_stnk_3, a.parkird_flag_3,
    			   a.parkird_type_4, a.parkird_plat_4, a.parkird_stnk_4, a.parkird_flag_4,
    			   to_char(b.contract_sdate,'dd/mm/yyyy') contract_sdate, to_char(b.contract_edate,'dd/mm/yyyy') contract_edate
    			from fm_parkir_det a, hrs b
    			where a.parkird_untuk_nik = b.id and parkird_reference='$cRequestNo'
        ";
        //echo $sql; //exit;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetail3CloseSrnKrjReq($cRequestNo){
        $sql 	= "
                SELECT A.CTRL_ID 
                FROM FM_ACCESS_CONTROL A, FM_CONTROL_CARD B 
                WHERE A.CTRL_ID = B.CTRL_ID 
                    and ctrl_reference='$cRequestNo'
        ";
        //echo $sql; //exit;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetail4CloseSrnKrjReq($cRequestNo){
        $sql 	= "
                SELECT TELP_EXT_EXT_TYPE, c.telp_ext_no, c.telp_ext_email, c.crtl_telp_id 
                FROM FM_ACCESS_CONTROL A, FM_CONTROL_TELP B, CONTROL_TELP_EXT C 
                WHERE A.CTRL_ID = B.CTRL_ID 
                    AND B.CTRL_TELP_ID = C.CRTL_TELP_ID 
                    AND A.CTRL_REFERENCE='$cRequestNo'
        ";
        //echo $sql; //exit;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetail5CloseSrnKrjReq($dataLogin){
        $job=$dataLogin['sesJob'];
        $sql 	= "
                select a.ri_id, a.ri_name, b.ri_desc, a.ri_jabatan_name, a.ri_status 
                from v_req_item a, fm_req_item_mst b 
                where a.ri_name = b.ri_name 
                    and a.ri_status='Y' 
                    and a.ri_jabatan_name = '$job' 
                order by ri_name desc
        ";
        //echo $sql; //exit;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetail6CloseSrnKrjReq($hReqFloor){
        $sql 	= "
                select mst_floor_desc 
                from fm_mst_floor 
                where mst_floor_desc='$hReqFloor' 
                order by mst_floor_desc asc
        ";
        //echo $sql; //exit;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetail7CloseSrnKrjReq($hReqFloor,$hReqRbfId){
        $sql 	= "
                select *  
                from fm_room_by_floor 
                where rbf_floor='$hReqFloor' 
                    and rbf_id='$hReqRbfId'
        ";
        //echo $sql; //exit;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function closeSrnKrjReqSave($arr){
        $pApproval=$arr['pApproval'];
        $pReqClosing=$arr['pReqClosing'];
        //echo $arr; exit;
        $sql 	= "
                update fm_req_head 
                set req_closing='$pApproval', req_closing_date=sysdate 
                where req_id='$pReqClosing'
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        
    }
    function getDetailCloseSrnKrjOvt($cRequestNo){
        //$job=$dataLogin['sesJob'];
        $sql 	= "
        SELECT hr2.NAME as ATASANNAME,
                hr3.NAME as NIKNAME,
                hr3.ORG as NIKORG,
                hr3.JOB_POSITION as NIKJOBPOSITION,
                hr4.NAME as NIPNAME,
                hr4.ORG as NIPORG,
                hr4.JOB_POSITION as NIPJOBPOSITION,
                tabelUtama.*
        FROM (
                select so_untuk_nik, so_nip, to_char(so_sdate,'dd/mm/yyyy') so_sdate, to_char(so_edate,'dd/mm/yyyy') so_edate, 
                substr(so_shour,1,2) so_shours, substr(so_shour,4,2) so_ehours, 
                substr(so_ehour,1,2) so_shoure, substr(so_ehour,4,2) so_ehoure, so_description, so_ac, so_comment, so_atasan_app, 
                so_lift, so_lighting, so_other, so_other_description, so_atasan_nik from fm_So where so_id='$cRequestNo'
        ) tabelUtama
        LEFT JOIN hrs hr2
            ON hr2.ID=tabelUtama.SO_ATASAN_NIK
        LEFT JOIN hrs hr3
            ON hr3.ID=tabelUtama.SO_UNTUK_NIK 
        LEFT JOIN hrs hr4
            ON hr4.ID=tabelUtama.SO_NIP        
        ";
        //echo $sql; //exit;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetail2CloseSrnKrjOvt($cRequestNo){
        //$job=$dataLogin['sesJob'];
        $sql 	= "
                select sod_id, sod_name, so_id, sod_floor, sod_location, sod_vendor_id, sod_vendor_name 
                from fm_so_det 
                where so_id='$cRequestNo'
        ";
        //echo $sql; //exit;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function closeSrnKrjOvtSave($arr){
        $pApproval=$arr['pApproval'];
        $pReqClosing=$arr['pReqClosing'];
        //echo $arr; exit;
        $sql 	= "
                update fm_so 
                set so_closing='$pApproval', so_closing_date=sysdate 
                where so_id='$pReqClosing'
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
    }
    function getDetailCloseSrnKrjPrk($cRequestNo){
        $sql 	= "
        SELECT hr3.NAME as NIKNAME,
                hr3.ORG as NIKORG,
                hr3.JOB_POSITION as NIKJOBPOSITION,
                hr4.NAME as UNIKNAME,
                hr4.ORG as UNIKORG,
                hr4.JOB_POSITION as UNIKJOBPOSITION,
                tabelUtama.*
        FROM(    
                select a.parkird_nik, a.parkird_untuk_nik, a.parkird_atasan_nik, a.parkird_type, a.parkird_plat, a.parkird_stnk, 
    			   a.parkird_date, a.parkird_description, a.parkird_file, a.parkird_use_by,  
    			   a.parkird_type_1, a.parkird_plat_1, a.parkird_stnk_1, a.parkird_flag_1, 
    			   a.parkird_type_2, a.parkird_plat_2, a.parkird_stnk_2, a.parkird_flag_2, 
    			   a.parkird_type_3, a.parkird_plat_3, a.parkird_stnk_3, a.parkird_flag_3, 
    			   a.parkird_type_4, a.parkird_plat_4, a.parkird_stnk_4, a.parkird_flag_4, 
    			   to_char(b.contract_sdate,'dd/mm/yyyy') contract_sdate, to_char(b.contract_edate,'dd/mm/yyyy') contract_edate 
    			from fm_parkir_det a, hrs b 
    			where a.parkird_untuk_nik = b.id 
                    and parkird_id='$cRequestNo'
        ) tabelUtama
        LEFT JOIN hrs hr3
            ON hr3.ID=tabelUtama.PARKIRD_NIK 
        LEFT JOIN hrs hr4
            ON hr4.ID=tabelUtama.PARKIRD_UNTUK_NIK  
        ";
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function closeSrnKrjPrkSave($arr){
        $pApproval=$arr['pApproval'];
        $pReqClosing=$arr['pReqClosing'];
        //echo $arr; exit;
        $sql 	= "
                update fm_parkir_det 
                set parkird_closing='$pApproval', parkird_closing_date=sysdate 
                where parkird_id='$pReqClosing'
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
    }
    function closeSrnKrjRmSave($arr){
        $pApproval=$arr['pApproval'];
        $pReqClosing=$arr['pReqClosing'];
        //echo $arr; exit;
        $sql 	= "
                update fm_rm set rm_closing='$pApproval', rm_closing_date=sysdate where rm_id='$pReqClosing'
        ";    
        //echo $sql; exit;        
        $query = $this->db->query($sql);
    }
    function getMsisdnRm($pReqClosing){
        $sql 	= "
                select msisdn from hrs where id = (select RM_UNTUK_NIK from fm_rm where rm_id='$pReqClosing')
        ";      
        $query = $this->db->query($sql);
        $res=$query->result_array();
        foreach($res as $nil){
            $hasil=$nil['MSISDN'];
        }
        //var_dump($hasil); exit;
        return $hasil;  
    }
    function getMsisdnPrk($pReqClosing){
        $sql 	= "
                select msisdn from hrs where id = (select PARKIRD_NIK from fm_parkir_det where parkird_id='$pReqClosing')
        ";      
        $query = $this->db->query($sql);
        $res=$query->result_array();
        foreach($res as $nil){
            $hasil=$nil['MSISDN'];
        }
        return $hasil;  
    }
    function getMsisdnAcc($pReqClosing){
        $sql 	= "
                select msisdn from hrs where id = (select CTRL_UNTUK_NIK from fm_access_control where ctrl_id='$pReqClosing')
        ";      
        $query = $this->db->query($sql);
        $res=$query->result_array();
        foreach($res as $nil){
            $hasil=$nil['MSISDN'];
        }
        return $hasil;  
    }
    function getMsisdnOvt($pReqClosing){
        $sql 	= "
                select msisdn from hrs where id = (select SO_UNTUK_NIK from fm_so where so_id='$pReqClosing')
        ";      
        $query = $this->db->query($sql);
        $res=$query->result_array();
        foreach($res as $nil){
            $hasil=$nil['MSISDN'];
        }
        return $hasil;  
    }
    function getMsisdnReq($pReqClosing){
        $sql 	= "
                select msisdn from hrs where id = (select REQ_UNTUK_NIK from fm_req_head where req_id='$pReqClosing')
        ";      
        $query = $this->db->query($sql);
        $res=$query->result_array();
        foreach($res as $nil){
            $hasil=$nil['MSISDN'];
        }
        return $hasil;  
    }
    function getMsisdnSik($pReqClosing){
        $sql 	= "
                select msisdn from hrs where id = (select SIK_UNTUK_NIK from fm_sik where sik_id='$pReqClosing')
        ";      
        $query = $this->db->query($sql);
        $res=$query->result_array();
        foreach($res as $nil){
            $hasil=$nil['MSISDN'];
        }
        return $hasil;  
    }
    function getDetailEditAcc($cRequestNo){
        $sql 	= "
        SELECT hr2.NAME as ATASANNAME,
                hr3.NAME as NIKNAME,
                hr3.ORG as NIKORG,
                hr3.JOB_POSITION as NIKJOBPOSITION,
                tabelUtama.*
        FROM( 
                select ctrl.CTRL_ID,
    				       ctrl.CTRL_UNTUK_NIK,
    				       (select card.CTRL_CARD_ID
    				        from FM_CONTROL_CARD card
    				        where card.CTRL_ID = ctrl.CTRL_ID) card,
    				       (select telp.CTRL_TELP_ID
    				        from FM_CONTROL_TELP telp
    				        where telp.CTRL_ID = ctrl.CTRL_ID) telp,
    				       ctrl.CTRL_SIK_NO,
    				       to_char(ctrl.CTRL_DATE_AWAL,'DD/MM/YYYY') CTRL_DATE_AWAL,
    				       to_char(ctrl.CTRL_DATE_AKHIR,'DD/MM/YYYY') CTRL_DATE_AKHIR,
    				       to_char(ctrl.DTMUPD,'DD/MM/YYYY') DTMUPD,
    				       ctrl.CTRL_ATASAN_ID,
    				       ctrl.CTRL_DESCRIPTION,
    					ctrl.CTRL_TELP_FISIK,
    					ctrl.CTRL_CARD_FISIK
    				from FM_ACCESS_CONTROL ctrl 
    				where ctrl.CTRL_ID = '$cRequestNo'
        ) tabelUtama
        LEFT JOIN hrs hr2
            ON hr2.ID=tabelUtama.CTRL_ATASAN_ID 
        LEFT JOIN hrs hr3
            ON hr3.ID=tabelUtama.CTRL_UNTUK_NIK
        ";
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetail2EditAcc(){
        //QUERY ORI SEMENTARA DISABLE, KARENA TERDAPAT DUPLIKASI FLOOR YANG MENGAKIBATKAN DELETE ULANG SETELAH SAVE JIKA DISUBMIT
        /*$sql 	= "
        select distinct flo.mst_floor_id,
		      flo.mst_floor_desc
		from fm_mst_floor flo
		where flo.mst_floor_status = 'Y'
        ";
        */
        $sql 	= "
        select distinct
		      flo.mst_floor_desc
		from fm_mst_floor flo
		where flo.mst_floor_status = 'Y'
        order by mst_floor_desc
        ";
        
        
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetail3EditAcc($vCtrlCard,$pValue){
        $sql 	= "
        select count(*) CNT
		      from CONTROL_CARD_FLOOR flo
		where flo.CARD_FLOOR_NAME = '$pValue'
		and flo.CRTL_CARD_ID = '$vCtrlCard'
        ";
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getTelpEditAcc($vCtrlTelp,$tipe){
        $sql 	= "
        select count(*) CNT
		from CONTROL_TELP_EXT ext
		where ext.CRTL_TELP_ID = '$vCtrlTelp' 
		and ext.TELP_EXT_EXT_TYPE = '$tipe'
        ";
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    
    
    //ACCESS CONTROL EDIT SAVE===========================START================================================
    
    function accUpdate1($arr){
        $pCtrlID			=  $arr['pCtrlID'];
    	$pCtrlCheck1 		=  $arr['pCtrlCheck1'];
    	$pCtrlCheck2 		=  $arr['pCtrlCheck2'];
    	$pCtrlLokal 		=  $arr['pCtrlLokal'];
    	$pCtrlSljj 			=  $arr['pCtrlSljj'];
    	$pCtrlSli 			=  $arr['pCtrlSli'];
    	$pCtrlCardFloor 	=  $arr['pCardFloor'];
    	$pCtrlUserType 		=  $arr['pCtrlUserType'];
    	$pCtrlUserName 		=  $arr['pNameFor'];
    	$pCtrlVendor		=  $arr['pDepartemenFor'];
    	$pCtrlDesc 			=  $arr['pCtrlDesc'];
    	$pAtasanNik			=  $arr['pAtasanNik'];
    	$pCtrlSik			=  $arr['pCtrlSik'];
    	$pDate1				=  $arr['pDate1'];
    	$pDate2				=  $arr['pDate2'];
    	$pNikFor			=  $arr['pNikFor'];
    	$pFloor				=  $arr['pFloor'];
        $pPhoneFisik		=  $arr['pPhoneFisik'];
    	$pCardFisik			=  $arr['pCardFisik'];
        $vDate1             = $arr['vDate1'];
    	$vDate2             = $arr['vDate2'];
        $sql 	= "
                update fm_access_control set ctrl_description = '$pCtrlDesc', 
    												  CTRL_ATASAN_ID = '$pAtasanNik', 
    												  CTRL_DATE_AWAL = to_date('$vDate1','dd/mm/yyyy'), 
    												  CTRL_DATE_AKHIR = to_date('$vDate2','dd/mm/yyyy'), 
    												  CTRL_SIK_NO = '$pCtrlSik',
    												  CTRL_TELP_FISIK = '$pPhoneFisik',
    												  CTRL_CARD_FISIK = '$pCardFisik'
    					 where ctrl_id = '$pCtrlID'
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
    }
    function accSelect1(){
        $sql 	= "
            select max(to_number(substr(CTRL_CARD_ID,1,5),'99999')) ctrl_card_id_old, rtrim(to_char(sysdate,'RM')) romawi 
            from fm_control_card
        ";
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function accSelect2($cCtrlCardIdNew,$cRomawi){
        $sql 	= "
            select lpad($cCtrlCardIdNew,5,0)||'/DOC/$cRomawi/'||TO_CHAR(SYSDATE,'YYYY') ctrl_card_id 
            from dual
        ";
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function accSelect3($arr){
        $pCtrlID			=  $arr['pCtrlID'];
        $sql 	= "
                select CTRL_CARD_ID
    		           from FM_CONTROL_CARD
    				   where CTRL_ID = '$pCtrlID'
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function accInsert1($arr,$cCtrCardlId){
        $pCtrlID			=  $arr['pCtrlID'];
    	$pCtrlCheck1 		=  $arr['pCtrlCheck1'];
    	$pCtrlCheck2 		=  $arr['pCtrlCheck2'];
    	$pCtrlLokal 		=  $arr['pCtrlLokal'];
    	$pCtrlSljj 			=  $arr['pCtrlSljj'];
    	$pCtrlSli 			=  $arr['pCtrlSli'];
    	$pCtrlCardFloor 	=  $arr['pCardFloor'];
    	$pCtrlUserType 		=  $arr['pCtrlUserType'];
    	$pCtrlUserName 		=  $arr['pNameFor'];
    	$pCtrlVendor		=  $arr['pDepartemenFor'];
    	$pCtrlDesc 			=  $arr['pCtrlDesc'];
    	$pAtasanNik			=  $arr['pAtasanNik'];
    	$pCtrlSik			=  $arr['pCtrlSik'];
    	$pDate1				=  $arr['pDate1'];
    	$pDate2				=  $arr['pDate2'];
    	$pNikFor			=  $arr['pNikFor'];
    	$pFloor				=  $arr['pFloor'];
        $pPhoneFisik		=  $arr['pPhoneFisik'];
    	$pCardFisik			=  $arr['pCardFisik'];
        $vDate1             = $arr['vDate1'];
    	$vDate2             = $arr['vDate2'];
        $sql 	= "
                insert into fm_control_card(ctrl_card_id, ctrl_id, ctrl_card_user, ctrl_card_user_type, ctrl_card_vendor) 
                values ('$cCtrCardlId', '$pCtrlID', '$pCtrlUserName','$pCtrlUserType', '$pCtrlVendor')
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
    }
    function accSelect4(){
        $sql 	= "
                select count(*) CNT_ROW
                from (
    				SELECT flo.mst_floor_id
    				from fm_mst_floor flo
    				where flo.mst_floor_status = 'Y'
    			group by flo.mst_floor_id )
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function accInsert2($pFloor,$cCtrCardlId){
        $sql 	= "
                insert into CONTROL_CARD_FLOOR(card_floor_id, card_floor_name, crtl_card_id) 
                values ((select max(card_floor_id)+1 testing from CONTROL_CARD_FLOOR), '$pFloor', '$cCtrCardlId')
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
    }
    function accDelete1($pFloor,$pCardId){
        $sql 	= "
                delete from CONTROL_CARD_FLOOR 
                where crtl_card_id = '$pCardId' 
                    and card_floor_name = '$pFloor'
        ";    
        //echo $sql; 
        $query = $this->db->query($sql);
    }
    function accSelect5(){
        $sql 	= "
                select count(*) CNT_ROW
			    from (
    				SELECT flo.mst_floor_id
    				from fm_mst_floor flo
    				where flo.mst_floor_status = 'Y'
    			group by flo.mst_floor_id)
        ";    
        //echo $sql;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function accInsert3($pFloor,$pCardId){
        $sql 	= "
                insert into CONTROL_CARD_FLOOR(card_floor_id, card_floor_name, crtl_card_id) values 
    			((select max(card_floor_id)+1 testing from CONTROL_CARD_FLOOR), '$pFloor', '$pCardId')
        ";    
        echo $sql;         
        $query = $this->db->query($sql);
    }
    function accDelete2($pFloor,$pCardId){
        $sql 	= "
                delete from CONTROL_CARD_FLOOR 
                where crtl_card_id = '$pCardId' and card_floor_name = '$pFloor'
        ";    
        echo $sql;        
        $query = $this->db->query($sql);
    }
    function accDelete3($arr){
        $pCtrlID			=  $arr['pCtrlID'];
        $sql 	= "
                delete from CONTROL_CARD_FLOOR 
                where CRTL_CARD_ID in (
                    select CTRL_CARD_ID 
                    from FM_CONTROL_CARD 
                    where CTRL_ID = '$pCtrlID')
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
    }
    function accDelete4($arr){
        $pCtrlID			=  $arr['pCtrlID'];
        $sql 	= "
                delete from FM_CONTROL_CARD 
                where CTRL_ID = '$pCtrlID'
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
    }
    function accSelect6(){
        $sql 	= "
                select max(to_number(substr(CTRL_TELP_ID,1,5),'99999')) ctrl_TELP_id_old, rtrim(to_char(sysdate,'RM')) romawi 
                from fm_control_telp
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function accSelect7($cCtrlTelpIdNew,$cRomawi){
        $sql 	= "
                select lpad($cCtrlTelpIdNew,5,0)||'/DOC/$cRomawi/'||TO_CHAR(SYSDATE,'YYYY') ctrl_telp_id 
                from dual
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function accSelect8($pCtrlID){
        $sql 	= "
                select CTRL_TELP_ID
                from fm_control_telp
    			where CTRL_ID = '$pCtrlID'
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function accInsert4($arr,$cCtrTelplId){
        $pCtrlID			=  $arr['pCtrlID'];
    	$pCtrlCheck1 		=  $arr['pCtrlCheck1'];
    	$pCtrlCheck2 		=  $arr['pCtrlCheck2'];
    	$pCtrlLokal 		=  $arr['pCtrlLokal'];
    	$pCtrlSljj 			=  $arr['pCtrlSljj'];
    	$pCtrlSli 			=  $arr['pCtrlSli'];
    	$pCtrlCardFloor 	=  $arr['pCardFloor'];
    	$pCtrlUserType 		=  $arr['pCtrlUserType'];
    	$pCtrlUserName 		=  $arr['pNameFor'];
    	$pCtrlVendor		=  $arr['pDepartemenFor'];
    	$pCtrlDesc 			=  $arr['pCtrlDesc'];
    	$pAtasanNik			=  $arr['pAtasanNik'];
    	$pCtrlSik			=  $arr['pCtrlSik'];
    	$pDate1				=  $arr['pDate1'];
    	$pDate2				=  $arr['pDate2'];
    	$pNikFor			=  $arr['pNikFor'];
    	$pFloor				=  $arr['pFloor'];
        $pPhoneFisik		=  $arr['pPhoneFisik'];
    	$pCardFisik			=  $arr['pCardFisik'];
        $vDate1             = $arr['vDate1'];
    	$vDate2             = $arr['vDate2'];
        $sql 	= "
                insert into fm_control_telp(ctrl_telp_id, ctrl_id, ctrl_telp_user, 
    			            ctrl_telp_user_type, ctrl_telp_vendor) 
                values ('$cCtrTelplId', '$pCtrlID', '$pCtrlUserName','$pCtrlUserType', '$pCtrlVendor')
        ";    
        //echo $sql;        
        $query = $this->db->query($sql);
    }
    function accInsert5($cCtrTelplId){
        $sql 	= "
            insert into CONTROL_TELP_EXT(telp_ext_id, TELP_EXT_EXT_TYPE, crtl_telp_id) 
            values ((select max(telp_ext_id)+1 testing from CONTROL_TELP_EXT), 'LOKAL', '$cCtrTelplId')        
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
    }
    function accInsert6($cCtrTelplId){
        $sql 	= "
            insert into CONTROL_TELP_EXT(telp_ext_id, TELP_EXT_EXT_TYPE, crtl_telp_id) 
            values ((select max(telp_ext_id)+1 testing from CONTROL_TELP_EXT), 'SLJJ', '$cCtrTelplId')        
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
    }
    function accInsert7($cCtrTelplId){
        $sql 	= "
            insert into CONTROL_TELP_EXT(telp_ext_id, TELP_EXT_EXT_TYPE, crtl_telp_id) 
            values ((select max(telp_ext_id)+1 testing from CONTROL_TELP_EXT), 'SLI', '$cCtrTelplId')        
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
    }
    function accInsert8($pTelpId){
        $sql 	= "
            insert into CONTROL_TELP_EXT(telp_ext_id, TELP_EXT_EXT_TYPE, crtl_telp_id) 
            values ((select max(telp_ext_id)+1 testing from CONTROL_TELP_EXT), 'LOKAL', '$pTelpId')        
        ";    
        //echo $sql; exit;         
        $query = $this->db->query($sql);
    }
    function accDelete5($pTelpId){
        $sql 	= "
                delete from CONTROL_TELP_EXT 
                where crtl_telp_id = '$pTelpId'
    			     and TELP_EXT_EXT_TYPE = 'LOKAL'
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
    } 
    function accInsert9($pTelpId){
        
        $sql 	= "
            insert into CONTROL_TELP_EXT(telp_ext_id, TELP_EXT_EXT_TYPE, crtl_telp_id) 
            values ((select max(telp_ext_id)+1 testing from CONTROL_TELP_EXT), 'SLJJ', '$pTelpId')       
        ";    
        //echo $sql;        
        $query = $this->db->query($sql);
    }   
    function accDelete6($pTelpId){
        $sql 	= "
                delete from CONTROL_TELP_EXT 
                where crtl_telp_id = '$pTelpId'
			         and TELP_EXT_EXT_TYPE = 'SLJJ'
        ";    
        //echo $sql;        
        $query = $this->db->query($sql);
    } 
    function accInsert10($pTelpId){
        $sql 	= "
            insert into CONTROL_TELP_EXT(telp_ext_id, TELP_EXT_EXT_TYPE, crtl_telp_id) 
            values ((select max(telp_ext_id)+1 testing from CONTROL_TELP_EXT), 'SLI', '$pTelpId')      
        ";    
        //echo $sql;        
        $query = $this->db->query($sql);
    }
    function accDelete7($pTelpId){
        $sql 	= "
                delete from CONTROL_TELP_EXT 
                where crtl_telp_id = '$pTelpId'
    			     and TELP_EXT_EXT_TYPE = 'SLI'
        ";    
        //echo $sql;        
        $query = $this->db->query($sql);
    } 
    function accDelete8($pCtrlID){
        $sql 	= "
                delete from CONTROL_TELP_EXT 
                where CRTL_TELP_ID in (
                    select CRTL_TELP_ID from FM_CONTROL_TELP 
                    where CTRL_ID = '$pCtrlID')
        ";    
        //echo $sql;        
        $query = $this->db->query($sql);
    } 
    function accDelete9($pCtrlID){
        $sql 	= "
                delete from FM_CONTROL_TELP 
                where CTRL_ID = '$pCtrlID'
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
    } 
    //ACCESS CONTROL EDIT SAVE===========================END================================================
    
    
    function getDetailEditOvt($cRequestNo){
        $sql 	= "
        SELECT hr2.NAME as ATASANNAME,
                hr3.NAME as NIKNAME,
                hr3.ORG as NIKORG,
                hr3.JOB_POSITION as NIKJOBPOSITION,
                tabelUtama.*
        FROM( 
                select so_untuk_nik, so_nip, to_char(so_sdate,'dd/mm/yyyy') so_sdate, to_char(so_edate,'dd/mm/yyyy') so_edate, 
                substr(so_shour,1,2) so_shours, substr(so_shour,4,2) so_ehours, 
                substr(so_ehour,1,2) so_shoure, substr(so_ehour,4,2) so_ehoure, so_description, so_ac, 
                so_lift, so_lighting, so_other, so_other_description, so_atasan_nik 
                from fm_So where so_id='$cRequestNo'
        ) tabelUtama
        LEFT JOIN hrs hr2
            ON hr2.ID=tabelUtama.SO_ATASAN_NIK 
        LEFT JOIN hrs hr3
            ON hr3.ID=tabelUtama.SO_UNTUK_NIK        
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getNik(){
        $sql 	= "
                select a.hr_id, b.name, b.org, b.job_position, b.status 
                from logins a, hrs b 
                where a.hr_id = b.id and upper(b.location) like 'HEAD OFFICE%' 
                order by b.name asc
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getAtasanNik(){
        $sql 	= "
                select a.hr_id, b.name from logins a, hrs b 
                where a.hr_id = b.id and (upper(b.job) in (select job from job_approval)) 
                and upper(b.city)='JAKARTA' 
                order by name asc
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getVendor(){
        $sql 	= "
                select vendor_id, vendor_name, PIC 
                from lkk_vendor_mst  
                order by vendor_name asc
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetailEditOvtVendor($cRequestNo){
        $sql 	= "
                select sod_id, sod_name, so_id, sod_floor, sod_location, sod_vendor_id, sod_vendor_name 
                from fm_so_det where so_id='$cRequestNo'
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getLantai(){
        $sql 	= "
                select distinct mst_floor_desc 
                from fm_mst_floor 
                where mst_floor_status='Y' 
                order by mst_floor_desc
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    
    //==
    
    function getAtasan(){
        $sql 	= "
                select a.hr_id, 
                    b.name, b.org, b.job, b.job_position, b.status 
                from logins a, 
                    hrs b 
                where a.hr_id = b.id
                    and (upper(b.job) in (select job from job_approval)) 
                    and upper(b.location) like 'HEAD OFFICE%'
                order by b.name asc 
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getReference(){
        $sql 	= "
                select sik_id, vendor_pic, to_char(SIK_SDATE,'DD/MM/YYYY') SIK_SDATE, to_char(SIK_EDATE, 'DD/MM/YYYY') SIK_EDATE 
                from fm_sik
                order by vendor_pic asc
        ";    
        //echo $sql;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //OVERTIME EDIT SAVE===========================START================================================
    
    function ovtUpdate1($arr){
            $pSoId    			= $arr['pSoId'];
            $pCType             = $arr['pCType'];
            $pNik    			= $arr['pNik'];
            $pSdate    			= $arr['pSdate'];
            $pEdate    			= $arr['pEdate'];
            $pShour    			= $arr['pShour'];
            $pEhour    			= $arr['pEhour'];
            $pSminute   		= $arr['pSminute'];
            $pEminute   		= $arr['pEminute'];
            $pAc    			= $arr['pAc'];
            $pLift    			= $arr['pLift'];
            $pLighting  		= $arr['pLighting'];
            $pOther  			= $arr['pOther'];
            $pOtherDescription  = $arr['pOtherDescription'];
            $pDescription  		= $arr['pDescription'];
            $pTotalDetail  		= $arr['pTotalDetail'];
            $pAtasanNik  		= $arr['pAtasanNik'];
            $pAtasanNama  		= $arr['pAtasanNama'];
            $pNikFor    		= $arr['pNikFor'];
            
            $pReqId    			= $arr['pReqId'];
            $pReqDetId    		= $arr['pReqDetId'];
            
            //UNTUK PILIHAN TABEL BAWAH
            $pSodId             = $arr['pSodId'];
            $pSodName           = $arr['pSodName'];
            $pSodFloor          = $arr['pSodFloor'];
            $pSodLocation       = $arr['pSodLocation'];
            $pSodVendorId       = $arr['pSodVendorId'];
        $sql 	= "
            update fm_so 
            set so_sdate=to_date('$pSdate','dd/mm/yyyy'),
                so_edate=to_date('$pEdate','dd/mm/yyyy'),
                so_shour='$pShour:$pSminute',
                so_ehour='$pEhour:$pEminute',
                so_ac	='$pAc',
                so_lift='$pLift',
                so_lighting='$pLighting',
                so_other='$pOther',
                so_other_description='$pOtherDescription',
                so_description='$pDescription', 
                so_untuk_nik = '$pNikFor', 
                so_atasan_nik='$pAtasanNik' 
            where so_id='$pSoId'
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    function ovtSelect1(){
        $sql 	= "
            select max(to_number(substr(so_id,1,5),'99999')) so_id_old, rtrim(to_char(sysdate,'RM')) romawi 
            from fm_so
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function ovtSelect2($cSoIdNew){
        $sql 	= "
            select lpad($cSoIdNew,5,0)||'/OVER/$cRomawi/'||TO_CHAR(SYSDATE,'YYYY') so_id 
            from dual
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function ovtInsert1($arr,$cSoId){
            $pSoId    			= $arr['pSoId'];
            $pCType             = $arr['pCType'];
            $pNik    			= $arr['pNik'];
            $pSdate    			= $arr['pSdate'];
            $pEdate    			= $arr['pEdate'];
            $pShour    			= $arr['pShour'];
            $pEhour    			= $arr['pEhour'];
            $pSminute   		= $arr['pSminute'];
            $pEminute   		= $arr['pEminute'];
            $pAc    			= $arr['pAc'];
            $pLift    			= $arr['pLift'];
            $pLighting  		= $arr['pLighting'];
            $pOther  			= $arr['pOther'];
            $pOtherDescription  = $arr['pOtherDescription'];
            $pDescription  		= $arr['pDescription'];
            $pTotalDetail  		= $arr['pTotalDetail'];
            $pAtasanNik  		= $arr['pAtasanNik'];
            $pAtasanNama  		= $arr['pAtasanNama'];
            $pNikFor    		= $arr['pNikFor'];
            
            $pReqId    			= $arr['pReqId'];
            $pReqDetId    		= $arr['pReqDetId'];
            
            //UNTUK PILIHAN TABEL BAWAH
            $pSodId             = $arr['pSodId'];
            $pSodName           = $arr['pSodName'];
            $pSodFloor          = $arr['pSodFloor'];
            $pSodLocation       = $arr['pSodLocation'];
            $pSodVendorId       = $arr['pSodVendorId'];
        $sql 	= "
            insert into fm_so
            (so_id, so_nip, so_untuk_nik, so_sdate, so_edate, so_shour, so_ehour, so_description, so_ac, so_lift, so_lighting, so_other, so_other_description, so_atasan_nik, so_reference, dtmupd) 
            values ('$cSoId','$pNik','$pNikFor',to_date('$pSdate','dd/mm/yyyy'),to_date('$pEdate','dd/mm/yyyy'),'$pShour:$pSminute','$pEhour:$pEminute','$pDescription','$pAc','$pLift','$pLighting','$pOther','$pOtherDescription','$pAtasanNik', '$pReqId', sysdate)
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    function ovtUpdate2($pReqId,$pReqDetId){
        $sql 	= "
            update fm_req_det 
            set req_det_app = 'Y' 
            where req_id='$pReqId' 
                and req_det_id= '$pReqDetId'
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    function ovtInsert2($pSodName,$pSodFloor,$pSodLocation,$pSodVendorId,$pSodVendorName,$cSoId){
        //MINE
        $sql 	= "
            insert into fm_so_det(sod_name, so_id, sod_floor, sod_location, sod_vendor_id) 
            values('$pSodName','$cSoId','$pSodFloor','$pSodLocation','$pSodVendorId','$pSodVendorName')
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    function ovtInsert3($pSodName,$pSodFloor,$pSodLocation,$pSodVendorId,$pSodVendorName,$pSoId){
        //MINE
        $sql 	= "
            insert into fm_so_det(sod_name, so_id, sod_floor, sod_location, sod_vendor_id, sod_vendor_name) 
            values('$pSodName','$pSoId','$pSodFloor','$pSodLocation','$pSodVendorId','$pSodVendorName')
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    function ovtUpdate3($pSodName,$pSodFloor,$pSodLocation,$pSodVendorId,$pSodVendorName,$pSodId){
        //MINE
        $sql 	= "
            update fm_so_det 
            set sod_name = '$pSodName', 
                sod_floor= '$pSodFloor', 
                sod_location= '$pSodLocation', 
                sod_vendor_id= '$pSodVendorId',
                sod_vendor_name='$pSodVendorName'
            where sod_id='$pSodId'
        ";   
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    
    
    //OVERTIME EDIT SAVE===========================END================================================
    
    //SIK EDIT FORM=========================================================================================    
    function getDetailEditSik($cRequestNo){
        $sql 	= "
            select hr2.NAME as ATASANNAME,
                    hr3.NAME as NIKNAME,
                    hr3.ORG as NIKORG,
                    hr3.JOB_POSITION as NIKJOBPOSITION,
            tabelUtama.*
            from(    
                select a.sik_untuk_nik, a.sik_atasan_nik, a.sik_id, a.sik_nik, to_char(a.sik_sdate,'dd/mm/yyyy') sik_sdate
                      , to_char(a.sik_edate,'dd/mm/yyyy') sik_edate, a.vendor_id, a.mst_floor_id, b.vendor_name, a.vendor_pic, 
                      substr(sik_shour,1,2) shours, substr(sik_shour,4,2) ehours, 
                      substr(sik_ehour,1,2) shoure, substr(sik_ehour,4,2) ehoure, a.vendor_jabatan 
                from fm_sik a, lkk_vendor_mst b 
                where a.vendor_id = b.vendor_id and a.sik_id='$cRequestNo'
            ) tabelUtama
            LEFT JOIN hrs hr2
                ON hr2.ID=tabelUtama.SIK_ATASAN_NIK
            LEFT JOIN hrs hr3
                ON hr3.ID=tabelUtama.SIK_UNTUK_NIK      
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetail2EditSik($cRequestNo){
        $sql 	= "
            select * 
            from fm_sik_job 
            where sik_id='$cRequestNo' 
            order by sikj_id asc
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getFloorEditSik(){
        $sql 	= "
            select distinct mst_floor_desc 
            from fm_mst_floor 
            where mst_floor_status='Y' 
            order by mst_floor_desc asc
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetailBawahSik($cRequestNo,$cSikjId){
        $sql 	= "
            select * 
            from fm_sik_job 
            where sik_id='$cRequestNo' 
                and sikj_id='$cSikjId'
            order by sikj_id asc
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //END SIK EDIT FORM=====================================================================================
    function getDetailBawahOvt($cRequestNo,$cSodId){
        $sql 	= "
            select sod_id, sod_name, so_id, sod_floor, sod_location, sod_vendor_id, sod_vendor_name 
            from fm_so_det 
            where so_id='$cRequestNo'
                and sod_id='$cSodId'    
            order by sod_id asc
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //SIK EDIT SAVE===========================START================================================
    function sikUpdate1($arr){
            $pCType    			=  $arr['pCType'];
            $pSikId    			=  $arr['pSikId'];
        	$pNik    			=  $arr['pNik'];
        	$pVendorId    		=  $arr['pVendorId'];
        	$pVendorName    	=  $arr['pVendorName'];
        	$pPic    			=  $arr['pPic'];
        	$pJabatan    		=  $arr['pJabatan'];
        	$pAtasanNik    		=  $arr['pAtasanNik'];
        	$pAtasanNama    	=  $arr['pAtasanNama'];
        	$pNikFor    		=  $arr['pNikFor'];
        	$pSdate    			=  $arr['pSdate'];
        	$pEdate    			=  $arr['pEdate'];
        	$pShour    			=  $arr['pShour'];
        	$pEhour    			=  $arr['pEhour'];
        	$pSminute    		=  $arr['pSminute'];
        	$pEminute    		=  $arr['pEminute'];
            $pJumlahI    		=  $arr['pJumlahI'];
        $sql 	= "
            update fm_sik 
            set mst_floor_id ='$pFloorId', 
                vendor_id ='$pVendorId', 
                vendor_pic ='$pPic', 
                vendor_jabatan ='$pJabatan', 
                sik_sdate = to_date('$pSdate','dd/mm/yyyy'), 
                sik_edate =to_date('$pEdate','dd/mm/yyyy'), 
                sik_shour ='$pShour:$pSminute', 
                sik_ehour ='$pEhour:$pEminute', 
                sik_untuk_nik = '$pNikFor', 
                sik_atasan_nik = '$pAtasanNik' 
            where sik_id ='$pSikId'
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    function sikSelect1(){
        $sql 	= "
            select max(to_number(substr(sik_id,1,5),'99999')) sik_id_old, rtrim(to_char(sysdate,'RM')) romawi 
            from fm_sik
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function sikSelect2($cSikIdNew,$cRomawi){
        $sql 	= "
            select lpad($cSikIdNew,5,0)||'/SIKA/$cRomawi/'||TO_CHAR(SYSDATE,'YYYY') sik_id 
            from dual
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function sikInsert1($arr,$cSikId){
        $pCType    			=  $arr['pCType'];
        $pSikId    			=  $arr['pSikId'];
        $pNik    			=  $arr['pNik'];
        $pVendorId    		=  $arr['pVendorId'];
        $pVendorName    	=  $arr['pVendorName'];
        $pPic    			=  $arr['pPic'];
        $pJabatan    		=  $arr['pJabatan'];
        $pAtasanNik    		=  $arr['pAtasanNik'];
        $pAtasanNama    	=  $arr['pAtasanNama'];
        $pNikFor    		=  $arr['pNikFor'];
        $pSdate    			=  $arr['pSdate'];
        $pEdate    			=  $arr['pEdate'];
        $pShour    			=  $arr['pShour'];
        $pEhour    			=  $arr['pEhour'];
        $pSminute    		=  $arr['pSminute'];
        $pEminute    		=  $arr['pEminute'];
        $pJumlahI    		=  $arr['pJumlahI'];
        $sql 	= "
            insert into fm_sik(sik_id, sik_nik, sik_untuk_nik, vendor_id, mst_floor_id, sik_sdate, sik_edate, sik_shour, sik_ehour, vendor_pic, vendor_jabatan, sik_atasan_nik, sik_reference, sik_create_date) 
            values ('$cSikId','$pNik','$pNikFor','$pVendorId','$pFloorId',to_date('$pSdate','dd/mm/yyyy'),to_date('$pEdate','dd/mm/yyyy'),'$pShour:$pSminute','$pEhour:$pEminute','$pPic','$pJabatan','$pAtasanNik', '$pReqId', sysdate)
        ";    
        echo $sql; //exit;         
        //$query = $this->db->query($sql);
    }
    function sikUpdate2($pReqId,$pReqDetId){
        $sql 	= "
            update fm_req_det set req_det_app = 'Y' 
            where req_id='$pReqId' 
                and req_det_id= '$pReqDetId'
        ";    
        echo $sql; //exit;         
        //$query = $this->db->query($sql);
    }
    function sikInsert2($pSikjName,$pSikjLocation,$pSikjFloor,$pSikjSn,$pSikjAccess,$pSikjDesc,$pSikjBarang,$cSikId){
        $sql 	= "
            insert into fm_sik_job(sik_id, sikj_name, sikj_location, sikj_floor, sikj_sn, sikj_access, sikj_desc, sikj_barang) 
            values 
            ('$cSikId','$pSikjName','$pSikjLocation','$pSikjFloor','$pSikjSn','$pSikjAccess','$pSikjDesc','$pSikjBarang')
        ";    
        echo $sql; //exit;         
        //$query = $this->db->query($sql);
    }
    function sikInsert3($pSikjName,$pSikjLocation,$pSikjFloor,$pSikjSn,$pSikjAccess,$pSikjDesc,$pSikjBarang,$pSikId){
        $sql 	= "
            insert into fm_sik_job(sik_id, sikj_name, sikj_location, sikj_floor, sikj_sn, sikj_access, sikj_desc, sikj_barang) 
            values 
            ('$pSikId','$pSikjName','$pSikjLocation','$pSikjFloor','$pSikjSn','$pSikjAccess','$pSikjDesc','$pSikjBarang')
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    
    function sikUpdate3($pSikjName,$pSikjLocation,$pSikjFloor,$pSikjSn,$pSikjAccess,$pSikjDesc,$pSikjBarang,$pSikjId){
        //MINE
        $sql 	= "
            update fm_sik_job 
            set sikj_name='$pSikjName', 
                sikj_location='$pSikjLocation', 
                sikj_floor='$pSikjFloor', 
                sikj_sn='$pSikjSn', 
                sikj_access='$pSikjAccess', 
                sikj_desc='$pSikjDesc', 
                sikj_barang='$pSikjBarang' 
            where sikj_id ='$pSikjId'
        ";   
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    function ovtUpdate9($pSodName,$pSodLocation,$pSodFloor,$pSodVendorId,$pSodId){
        //MINE
        $sql 	= "
            update fm_sik_job 
            set sikj_name='$pSikjName', 
                sikj_location='$pSikjLocation', 
                sikj_floor='$pSikjFloor', 
                sikj_sn='$pSikjSn', 
                sikj_access='$pSikjAccess', 
                sikj_desc='$pSikjDesc', 
                sikj_barang='$pSikjBarang' 
            where sikj_id ='$pSikjId'
        ";   
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    function sikDelete1($pSikjId){
        //MINE
        $sql 	= "
            delete from fm_sik_job  
            where sikj_id ='$pSikjId'
        ";   
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    
    
    //SIK EDIT SAVE===========================END================================================
    
    //SIK PARKIR FORM=========================================================================================    
    function getDetailEditPrk($pParkirdId){
        $sql 	= "
            select hr2.NAME as ATASANNAME,
                    hr3.NAME as NIKNAME,
                    hr3.ORG as NIKORG,
                    hr3.JOB_POSITION as NIKJOBPOSITION,
            tabelUtama.*
            from(    
                select a.parkird_nik, a.parkird_untuk_nik, a.parkird_atasan_nik, a.parkird_type, a.parkird_plat, a.parkird_stnk,
			       a.parkird_date, a.parkird_description, a.parkird_file, a.parkird_use_by,
			       a.parkird_type_1, a.parkird_plat_1, a.parkird_stnk_1, a.parkird_flag_1,
			       a.parkird_type_2, a.parkird_plat_2, a.parkird_stnk_2, a.parkird_flag_2,
			       a.parkird_type_3, a.parkird_plat_3, a.parkird_stnk_3, a.parkird_flag_3,
				   a.parkird_type_4, a.parkird_plat_4, a.parkird_stnk_4, a.parkird_flag_4,
			       to_char(b.contract_sdate,'dd/mm/yyyy') contract_sdate, to_char(b.contract_edate,'dd/mm/yyyy') contract_edate
				from fm_parkir_det a, hrs b
				where a.parkird_untuk_nik = b.id and parkird_id='$pParkirdId'
            ) tabelUtama
            LEFT JOIN hrs hr2
                ON hr2.ID=tabelUtama.PARKIRD_ATASAN_NIK
            LEFT JOIN hrs hr3
                ON hr3.ID=tabelUtama.PARKIRD_UNTUK_NIK      
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    
    //END PARKIR EDIT FORM=====================================================================================
    //PARKIR EDIT SAVE===========================START================================================
    function prkSelect1(){
        $sql 	= "
            select max(parkird_filename) xx 
            from fm_parkir_det 
            where lower(parkird_filename) like 'park_%'
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function prkUpdate1($arr){
        $pParkirdId=$arr['pParkirdId'];
        $pCType=$arr['pCType'];
        $pStatus=$arr['pStatus'];
        $pStatus=$arr['pReqId'];
        $pStatus=$arr['pReqDetId'];
        $msg=$arr['msg'];
        $pNik=$arr['pNik'];
        $pNikFor=$arr['pNikFor']; //
        $pStatusFor=$arr['pStatusFor'];
        $pAktif=$arr['pAktif'];
            $pParkirType1=$arr['pParkirType1'];
            $pStnk1=$arr['pStnk1'];
            $pPlat1=$arr['pPlat1'];
            $pParkirType2=$arr['pParkirType2'];
            $pStnk2=$arr['pStnk2'];
            $pPlat2=$arr['pPlat2'];
            $pParkirType3=$arr['pParkirType3'];
            $pStnk3=$arr['pStnk3'];
            $pPlat3=$arr['pPlat3'];
            $pParkirType4=$arr['pParkirType4'];
            $pStnk4=$arr['pStnk4'];
            $pPlat4=$arr['pPlat4'];
        $pFile=$arr['pFile'];
            $tmpname=$arr['tmpname'];
            $filename=$arr['filename'];
            $filesize=$arr['filesize'];
            $filetype=$arr['filetype'];
            $fname=$arr['fname'];
        $pAtasanNik=$arr['pAtasanNik'];
        $pAtasanNama=$arr['pAtasanNama'];
        $pDescription=$arr['pDescription'];
        
        
        
        $pParkirType=$arr['pParkirType'];
        $pPlat=$arr['pPlat'];
        $pStnk=$arr['pStnk'];
            //$arr['pFlag1'] = 'Y';
        
        $sql 	= "
            update fm_parkir_det 
            set parkird_nik		= '$pNik', 
                parkird_untuk_nik	= '$pNikFor', 
                parkird_use_by 	= '$pStatusFor', 
                parkird_type 		= '$pParkirType', 
                parkird_plat 		= '$pPlat', 
                parkird_stnk 		= '$pStnk', 
                parkird_type_1 	= '$pParkirType1', 
                parkird_plat_1 	= '$pPlat1', 
                parkird_stnk_1 	= '$pStnk1', 
                parkird_type_2 	= '$pParkirType2', 
                parkird_plat_2 	= '$pPlat2', 
                parkird_stnk_2 	= '$pStnk2', 
                parkird_type_3 	= '$pParkirType3', 
                parkird_plat_3 	= '$pPlat3', 
                parkird_stnk_3 	= '$pStnk3', 
                parkird_type_4 	= '$pParkirType4', 
                parkird_plat_4 	= '$pPlat4', 
                parkird_stnk_4 	= '$pStnk4', 
                parkird_description='$pDescription', 
                parkird_atasan_nik= '$pAtasanNik', 
                parkird_reference = '$pReqId', 
                parkird_date 		= sysdate, 
                parkird_file      = '$filename',
                parkird_filename  = '$fname',
                parkird_filetype  = '$filetype', 
                parkird_size      = '$filesize' 
            where parkird_id 	= '$pParkirdId' 
        ";    
        echo $sql; //exit;         
        //$query = $this->db->query($sql);
    }
    
    function prkUpdate2($arr){
        $pParkirdId=$arr['pParkirdId'];
        $pCType=$arr['pCType'];
        $pStatus=$arr['pStatus'];
        $pStatus=$arr['pReqId'];
        $pStatus=$arr['pReqDetId'];
        $msg=$arr['msg'];
        $pNik=$arr['pNik'];
        $pNikFor=$arr['pNikFor']; //
        $pStatusFor=$arr['pStatusFor'];
        $pAktif=$arr['pAktif'];
            $pParkirType1=$arr['pParkirType1'];
            $pStnk1=$arr['pStnk1'];
            $pPlat1=$arr['pPlat1'];
            $pParkirType2=$arr['pParkirType2'];
            $pStnk2=$arr['pStnk2'];
            $pPlat2=$arr['pPlat2'];
            $pParkirType3=$arr['pParkirType3'];
            $pStnk3=$arr['pStnk3'];
            $pPlat3=$arr['pPlat3'];
            $pParkirType4=$arr['pParkirType4'];
            $pStnk4=$arr['pStnk4'];
            $pPlat4=$arr['pPlat4'];
        $pFile=$arr['pFile'];
            $tmpname=$arr['tmpname'];
            $filename=$arr['filename'];
            $filesize=$arr['filesize'];
            $filetype=$arr['filetype'];
            $fname=$arr['fname'];
        $pAtasanNik=$arr['pAtasanNik'];
        $pAtasanNama=$arr['pAtasanNama'];
        $pDescription=$arr['pDescription'];
        
        
        
        $pParkirType=$arr['pParkirType'];
        $pPlat=$arr['pPlat'];
        $pStnk=$arr['pStnk'];
            //$arr['pFlag1'] = 'Y';
        
        $sql 	= "
            update fm_parkir_det 
            set parkird_nik		= '$pNik', 
                parkird_untuk_nik	= '$pNikFor', 
                parkird_use_by 	= '$pStatusFor', 
                parkird_type 		= '$pParkirType', 
                parkird_plat 		= '$pPlat', 
                parkird_stnk 		= '$pStnk', 
                parkird_type_1 	= '$pParkirType1', 
                parkird_plat_1 	= '$pPlat1', 
                parkird_stnk_1 	= '$pStnk1', 
                parkird_type_2 	= '$pParkirType2', 
                parkird_plat_2 	= '$pPlat2', 
                parkird_stnk_2 	= '$pStnk2', 
                parkird_type_3 	= '$pParkirType3', 
                parkird_plat_3 	= '$pPlat3', 
                parkird_stnk_3 	= '$pStnk3', 
                parkird_type_4 	= '$pParkirType4', 
                parkird_plat_4 	= '$pPlat4', 
                parkird_stnk_4 	= '$pStnk4', 
                parkird_description='$pDescription', 
                parkird_atasan_nik= '$pAtasanNik', 
                parkird_reference = '$pReqId', 
                parkird_date 		= sysdate 
            where parkird_id 	= '$pParkirdId' 
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    //PARKIR EDIT SAVE===========================END================================================
    
    //REPAIR MAINTENANCE EDIT FORM=========================================================================================    
    function getDetailEditRm($pRmID){
        $sql 	= "
            select hr2.NAME as ATASANNAME,
                    hr3.NAME as NIKNAME,
                    hr3.ORG as NIKORG,
                    hr3.JOB_POSITION as NIKJOBPOSITION,
            tabelUtama.*
            from(    
                
                SELECT rm.rm_id, 
    	               rm.rm_date, 
    			       rm.rm_type, 
    				   rm.rm_category, 
    			       rm.rm_vendor, 
    				   rm.rm_atasan_app, 
    			       rm.rm_ga_app, 
    				   rm.rm_floor,
    				   rm.RM_DESCRIPTION,
    				   rm.RM_SERIAL,
    				   rm.RM_SUITE,
    				   rm.RM_SHOUR,
    				   rm.RM_SMINUTE,
    				   rm.RM_EHOUR,
    				   rm.RM_EMINUTE,
    				   to_char(rm.RM_RETURN,'DD/MM/YYYY') as RM_RETURN,
    				   to_char(rm.RM_DELIVERY,'DD/MM/YYYY') as RM_DELIVERY,
    				   rm.RM_UNTUK_NIK,
    				   rm.RM_ATASAN_ID,
    				   (select MST_TYPE_ID
    				    from fm_mst_type
    					where upper(mst_type_desc) = upper(rm.rm_type)) as MST_TYPE_ID
    			FROM fm_rm rm
    			WHERE rm.rm_id = '$pRmID'
                
                
            ) tabelUtama
            LEFT JOIN hrs hr2
                ON hr2.ID=tabelUtama.RM_ATASAN_ID
            LEFT JOIN hrs hr3
                ON hr3.ID=tabelUtama.RM_UNTUK_NIK      
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getTypeRm(){
        $sql 	= "
            select mastype.MST_TYPE_ID as key, mastype.MST_TYPE_DESC as value 
            from FM_MST_TYPE mastype 
            where mastype.mst_type_status = 'Y'    
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getCategoryFromType($vType){
        $sql 	= "
            select mascateg.MST_CATEGORY_ID as key,
				  mascateg.MST_CATEGORY_DESC as value,
				  (select flo.MST_FLOOR_DESC
				   from fm_mst_floor flo
				   where flo.MST_FLOOR_ID = mascateg.MST_FLOOR_ID) as floor_desc,
				  (select flo.MST_FLOOR_DESC
				   from fm_mst_floor flo
				   where flo.MST_FLOOR_ID = mascateg.MST_FLOOR_ID)||' - '|| mascateg.MST_CATEGORY_DESC gab
		   from FM_MST_CATEGORY mascateg where mascateg.mst_CATEGORY_status = 'Y' and mascateg.MST_TYPE_ID = '$vType' 
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
        
    }
    function getFloorFromCategory($room_name){
        /*$sql 	= "
            select mascateg.MST_CATEGORY_ID as key,
				  mascateg.MST_CATEGORY_DESC as value,
				  (select flo.MST_FLOOR_DESC
				   from fm_mst_floor flo
				   where flo.MST_FLOOR_ID = mascateg.MST_FLOOR_ID) as floor_desc,
				  (select flo.MST_FLOOR_DESC
				   from fm_mst_floor flo
				   where flo.MST_FLOOR_ID = mascateg.MST_FLOOR_ID)||' - '|| mascateg.MST_CATEGORY_DESC gab
		   from FM_MST_CATEGORY mascateg 
           where mascateg.mst_CATEGORY_status = 'Y' and mascateg.MST_TYPE_ID = '$typid'
            AND mascateg.MST_CATEGORY_ID='$vCategory'
        ";*/
        
        $sql = " 
				SELECT f.MST_FLOOR_DESC FROM fm_mst_category c
				INNER JOIN fm_mst_floor f ON f.MST_FLOOR_ID = c.MST_FLOOR_ID 
				AND f.MST_TYPE_ID = c.MST_TYPE_ID 
				WHERE c.MST_CATEGORY_STATUS = 'Y' 
				AND c.MST_CATEGORY_ID = '$room_name'  
		";    
        $result = $this->db->query($sql);
		$Udata 	= $result->row_array();
		$Rdata 	= $result->num_rows();
		if ($Rdata > 0)
		{
			return $Udata;
		}
		else
		{
			return FALSE;
		}
        
    }
    //END REPAIR MAINTENANCE EDIT FORM=====================================================================================
    //REPAIRMAINTENANCE EDIT SAVE===========================START================================================
    function rmUpdate1($arr){
        $pRmID			=  $arr['pRmID'];
        $pCType			=  $arr['pCType'];
    	$pRmType 		=  $arr['pRmType'];
    	$pRmCategory 	=  $arr['pRmCategory'];
    	$pRmDesc 		=  str_replace("'", "''", $arr['pRmDesc']);
    	$pRmSerial 		=  $arr['pRmSerial'];
    	$pTrAtasanNik	=  $arr['pAtasanNik'];
    	$pRmFloor 		=  $arr['pRmFloor'];
    	$pRmDate1 		=  $arr['pRmDate1'];
    	$pRmDate2 		=  $arr['pRmDate2'];
    	$pNikFor		=  $arr['pNikFor'];
        $sql 	= "
            update fm_rm 
            set rm_description = '$pRmDesc', 
    			rm_serial = '$pRmSerial', 
    			rm_floor = '$pRmFloor',
    			rm_type = '$pRmType', 
    			rm_category = '$pRmCategory', 
    			rm_delivery = to_date('$pRmDate1','dd/mm/yyyy'), 
    			rm_return = to_date('$pRmDate2','dd/mm/yyyy'), 
    			RM_ATASAN_ID = '$pTrAtasanNik'
  			where rm_id = '$pRmID'
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    //REPAIRMAINTENANCE EDIT SAVE===========================END================================================
    
    //REQUEST GA EDIT FORM==================================START====================================================    
    function getDetailEditReq($pReqId){
        $sql 	= "
            select hr2.NAME as ATASANNAME,
                    hr3.NAME as NIKNAME,
                    hr3.ORG as NIKORG,
                    hr3.JOB as NIKJOB,
                    hr3.JOB_POSITION as NIKJOBPOSITION,
            tabelUtama.*
            from(    
                
                select req_id, req_date, req_description, req_nik, req_untuk_nik, req_atasan_nik, req_floor, req_rbf_id, req_info_hrd 
                from fm_req_head 
                where req_id='$pReqId'
                
            ) tabelUtama
            LEFT JOIN hrs hr2
                ON hr2.ID=tabelUtama.REQ_ATASAN_NIK
            LEFT JOIN hrs hr3
                ON hr3.ID=tabelUtama.REQ_UNTUK_NIK      
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //REQUEST GA EDIT FORM================================END=================================================
    //REQUEST GA EDIT SAVE===========================START================================================
    function reqUpdate1($arr){
        $pReqId    			=  $arr['pReqId'];
    	$pReqDescription    =  $arr['pReqDescription'];
    	$pReqInfoHrd    	=  $arr['pReqInfoHrd'];
    	$pNik    			=  $arr['pNik'];
    	$pNikFor    		=  $arr['pNikFor'];
    	$pAtasanNik    		=  $arr['pAtasanNik'];
    	$pAtasanName    	=  $arr['pAtasanName'];
    	$cJob  				=  $arr['pJobPosition'];
        $sql 	= "
            update fm_req_head 
            set req_description='$pReqDescription', 
                req_info_hrd='$pReqInfoHrd',  
                req_atasan_nik='$pAtasanNik', 
                req_date=sysdate 
            where req_id='$pReqId' 
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    //REQUEST GA EDIT SAVE===========================END================================================
    
//-----------------------------------------------------------PUBLIC ROOM---------------------------------------------------------------------------------    
    //MAILLING ROOM EDIT FORM==================================START====================================================    
    function getDetailEditMail($pDmrId){
        $sql 	= "
            select dmr.DMR_ID,
				       dmr.DMR_UNTUK_NIK,
				       dmr.DMR_COURIER_TYPE,
				       dmr.DMR_TUJUAN,
				       dmr.DMR_REGIONAL,
				       dmr.DMR_PENJEMPUTAN,
				       dmr.DMR_FLOOR,
				       dmr.DMR_TYPE,
				       dmr.DMR_CATEGORY,
				       dmr.DMR_WAKTU_PENJEMPUTAN,
				       dmr.DMR_ATASAN_APP_ID,
				       dmr.DMR_DESCRIPTION,
				       hr.ID,
				       hr.NAME,
				       hr.ORG,
				       hr.JOB,
					   (select hr.name
					    from hrs hr 
						where hr.id = dmr.DMR_ATASAN_APP_ID) atasan
				from fm_dmr dmr inner join hrs hr
                on dmr.DMR_UNTUK_NIK = hr.ID
				where dmr.DMR_ID = '$pDmrId'     
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getArea($cond)
	{
		$sql 	= " SELECT DISTINCT(AREA_NAME)
					FROM FM_MST_AREA
					WHERE AREA_STATUS = 'Y' ".$cond."
					ORDER BY AREA_NAME ASC";
				
		$result = $this->db->query($sql);
		$Udata 	= $result->result_Array();
		$Rdata 	= $result->num_rows();
		if ($Rdata > 0)
		{
			return $Udata;
		}
		else
		{
			return FALSE;
		}
	}
    //MAILLING ROOM EDIT FORM================================END=================================================
    //MAILLING ROOM EDIT SAVE===========================START================================================
    function mailUpdate1($arr){
        $pDmTujuan 		=  $arr['pDmTujuan'];
    	$pDmType 		=  $arr['pDmType'];
    	$pDmDesc 		=  $arr['pDmDesc'];
    	$pDmBerat		=  $arr['pDmBerat'];
    	$pAtasanNik		=  $arr['pAtasanNik'];
        $pAtasanName	=  $arr['pAtasanName'];
    	$pDmRegional	=  $arr['pDmRegional'];
    	$pDmLokasi		=  $arr['pDmLokasi'];
    	$pDmFloor		=  $arr['pDmFloor'];
    	$pDmCategory	=  $arr['pDmCategory'];
    	$pDmTime		=  $arr['pDmTime'];
    	$pJasaKurir		=  $arr['pJasaKurir'];
    	$pDmrId			=  $arr['pDmrId'];
        $pCType			=  $arr['pCType'];
        $sql 	= "
            update fm_dmr dmr 
            set	dmr.dmr_tujuan = '$pDmTujuan', 
    	        dmr.dmr_penjemputan  = '$pDmLokasi',
    			dmr.dmr_description = '$pDmDesc', 
    			dmr.dmr_type = '$pDmType', 
    			dmr.DMR_ATASAN_APP_ID = '$pAtasanNik', 
    			dmr.DMR_FLOOR = '$pDmFloor', 
    			dmr.DMR_CATEGORY = '$pDmCategory', 
    			dmr.DMR_WAKTU_PENJEMPUTAN = '$pDmTime' , 
    			dmr.DMR_COURIER_TYPE = '$pJasaKurir', 
    			dmr.DMR_REGIONAL = '$pDmRegional'
			where dmr.DMR_ID = '$pDmrId'
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    //MAILLING ROOM EDIT SAVE===========================END================================================
    //MEETING ROOM EDIT FORM==================================START====================================================    
    function getDetailEditMeet($pRoomId){
        $sql 	= "
            select metrom.room_id,
					     metrom.room_jenis,
						 metrom.room_type,
						 to_char(metrom.room_date,'dd/mm/yyyy') room_date,
						 metrom.room_shour,
						 metrom.room_sminute,
						 metrom.room_ehour,
						 metrom.room_eminute,
						 metrom.room_description,
						 metrom.room_floor,
						 hr.id,
						 hr.name,
						 hr.org,
						 hr.job_position,
						 metrom.room_condition,
						 metrom.ROOM_PARTICIPANT,
						 (select detpr.PRM_REQUISITION_ID
						  from FM_MEETING_ROOM_DET_PR detpr
						  where detpr.room_id = metrom.room_id) as prno
                  from fm_meeting_room metrom inner join hrs hr
											  on metrom.usrupd = hr.id
				  where metrom.room_id = '$pRoomId'    
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    
    function getDetailEditMeet2($pRoomId){
        $sql 	= "
            select romdet.roomd_description,
			   romdet.roomd_qty
    		from fm_meeting_room_det romdet
    		where romdet.room_id = '$pRoomId'
    		   and romdet.ROOMD_STATUS = 'Y'    
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getTime(){
        $sql 	= "
            select tm.time_id,
			     tm.time_name
			from fm_mst_time tm 
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    
    //MEETING ROOM EDIT FORM================================END=================================================
    //MEETING ROOM EDIT SAVE===========================START================================================
    function meetUpdate1($arr){
        $pCType			=  $arr['pCType'];
        $vRoomId		=  $arr['vRoomId'];
    	$pStrHour		=  $arr['pStrHour'];
    	$pEndHour		=  $arr['pEndHour'];
    	$pAction		=  $arr['pAction'];
        $pSTime1 = strtoupper(substr($pStrHour,0,2)) ;
    	$pSTime2 = strtoupper(substr($pStrHour,3,2)) ;
    	
    	$pETime1 = strtoupper(substr($pEndHour,0,2)) ;
    	$pETime2 = strtoupper(substr($pEndHour,3,2)) ;
        $sql 	= "
            update FM_MEETING_ROOM 
            set ROOM_SHOUR = '$pSTime1', 
                ROOM_SMINUTE = '$pSTime2', 
                ROOM_EHOUR = '$pETime1', 
                ROOM_EMINUTE = '$pETime2' 
            where ROOM_ID = '$vRoomId'
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    function meetDelete1($vRoomId){
        $sql 	= "
            delete from FM_MEETING_ROOM_DET_PR 
            where ROOM_ID = '$vRoomId'
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    function meetDelete2($vRoomId){
        $sql 	= "
            delete from FM_MEETING_ROOM_DET 
            where ROOM_ID = '$vRoomId'
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    function meetDelete3($vRoomId){
        $sql 	= "
            delete from FM_MEETING_ROOM 
            where ROOM_ID = '$vRoomId'
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    //MEETING ROOM EDIT SAVE===========================END================================================
//-----------------------------------------------------------PUBLIC ROOM END------------------------------------------------------------------------------    

//-----------------------------------------------------------SERVICES START-------------------------------------------------------------------------------
    //SARAN KELUHAN EDIT FORM==================================START====================================================    
    function getDetailEditSarKel($pPoboxId){
        $sql 	= "
            select hr2.NAME as ATASANNAME,
                    hr3.NAME as NIKNAME,
                    hr3.ORG as NIKORG,
                    hr3.JOB as NIKJOB,
                    hr3.JOB_POSITION as NIKJOBPOSITION,
            tabelUtama.*
            from(    
                
                select a.pobox_relatedto,
                        a.pobox_atasan_nik, 
                        a.pobox_id, a.pobox_nip,
                        a.pobox_untuk_nik,
                        a.pobox_type, 
                        a.pobox_subject, 
                        a.pobox_description, 
                        a.type_id, 
                        b.mst_type_desc 
                from fm_pobox a, 
                        fm_mst_type b 
                where a.type_id = b.mst_type_id 
                        and a.pobox_id='$pPoboxId'
                
                
            ) tabelUtama
            LEFT JOIN hrs hr2
                ON hr2.ID=tabelUtama.POBOX_ATASAN_NIK
            LEFT JOIN hrs hr3
                ON hr3.ID=tabelUtama.POBOX_UNTUK_NIK  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    
    function getDetailEditSarKel2(){
        $sql 	= "
            select * 
            from fm_mst_type 
            order by mst_type_desc asc   
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    
    //SARAN KELUHAN EDIT FORM================================END=================================================
    //SARAN KELUHAN EDIT SAVE===========================START================================================
    function sarKelUpdate1($arr){
        $pCType      		=  $arr['pCType'];
        $pPoboxId    		=  $arr['pPoboxId'];
    	$pNik    			=  $arr['pNik'];
    	$pType    			=  $arr['pType'];
    	$pCriteria    		=  $arr['pCriteria'];
    	$pSubject    		=  $arr['pSubject'];
    	$pDescription  		=  $arr['pDescription'];
    	$pAtasanNik    		=  $arr['pAtasanNik'];
    	$pAtasanNama    	=  $arr['pAtasanNama'];
    	$pNikFor    		=  $arr['pNikFor'];
    	$pRelatedTo    		=  $arr['pRelatedTo'];
        $sql 	= "
            update fm_pobox 
                set pobox_type='$pCriteria', 
                type_id='$pType', 
                pobox_subject='$pSubject',
                pobox_description='$pDescription',
                pobox_untuk_nik='$pNikFor', 
                pobox_relatedto='$pRelatedTo' 
            where pobox_id='$pPoboxId'
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    
    //SARAN KELUHAN EDIT SAVE===========================END================================================
    
    //ORDER EQUIPMENT EDIT FORM==================================START====================================================    
    function getDetailEditOrder($pOrderId){
        $sql 	= "
            select hr2.NAME as ATASANNAME,
                    hr3.NAME as NIKNAME,
                    hr3.ORG as NIKORG,
                    hr3.JOB as NIKJOB,
                    hr3.JOB_POSITION as NIKJOBPOSITION,
            tabelUtama.*
            from(    
                
                select order_id, hr_id, order_description, 
                       to_char(order_tgl_awal,'dd/mm/yyyy') order_tgl_awal, to_char(order_tgl_akhir,'dd/mm/yyyy') order_tgl_akhir, 
                       order_date, order_for, ORDER_ATASAN_ID, ORDER_ATASAN_APP, ORDER_ATASAN_APP_DATE
                from fm_order_header
                where order_id='$pOrderId'
                
                
            ) tabelUtama
            LEFT JOIN hrs hr2
                ON hr2.ID=tabelUtama.ORDER_ATASAN_ID
            LEFT JOIN hrs hr3
                ON hr3.ID=tabelUtama.HR_ID  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    
    function getDetailEditOrder2($pOrderId){
        $sql 	= "
            select order_id, order_det_id,
			     warehouse_name, warehouse_id, 
			     order_det_qty, order_det_STATUS
            from fm_order_detail
            where order_id='$pOrderId'  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetailEditOrder2Other($pOrderId){
        $sql 	= "
            select order_id, order_det_id,
			     warehouse_name, warehouse_id, 
			     order_det_qty, order_det_STATUS
            from fm_order_detail
            where order_id='$pOrderId'  
                and warehouse_id='00004/DOC/XII/2008'
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetailEditOrderItem($pOrderId){
        $sql 	= "
            select house.warehouse_id as warehouse_id,
					house.warehouse_item_name as warehouse_item_name,
					house.warehouse_item_qty as warehouse_item_qty,
					house.warehouse_item_qty_in as warehouse_item_qty_in,
					house.warehouse_item_qty_out as warehouse_item_qty_out
			from fm_warehouse house
			where house.warehouse_item_status = 'Y'
			and house.WAREHOUSE_ITEM_QTY_IN > 0  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetailEditOrder3($pOrderId,$itemId){
        $sql 	= "
            select count(*) as CNT, sum(ORDER_DET_QTY) as ORDER_DET_QTY
            from fm_order_detail
            where order_id='$pOrderId' 
                and warehouse_id='$itemId' 
                and warehouse_id<>'00004/DOC/XII/2008'
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    
    //ORDER EQUIPMENT EDIT FORM================================END=================================================
    //ORDER EQUIPMENT EDIT SAVE===========================START================================================
    function orderUpdate1($arr){
        $pCType			    =  $arr['pCType'];
        $pOrderId    		=  $arr['pOrderId'];
        $pHrId   			=  $arr['pHrId'];
        $pDesc    			=  $arr['pDesc'];
        $pTglAwal    		=  $arr['pTglAwal'];
        $pTglAkhir    		=  $arr['pTglAkhir'];
        $pOrderFor    		=  $arr['pOrderFor'];
        $pAtasanId    	    =  $arr['pAtasanId'];
        $pAtasanApp   		=  $arr['pAtasanApp'];
        $pJumlahItem   		=  $arr['pJumlahItem'];
        $pItemCek    		=  $arr['pItemCek'];
        $pItemId    		=  $arr['pItemId'];
        $pItemName    	    =  $arr['pItemName'];
        $pItemQty   		=  $arr['pItemQty'];
        $pOtherId    	    =  $arr['pOtherId'];
        $pOtherName   		=  $arr['pOtherName'];
                                          
        $sql 	= "
            update fm_order_header 
                set hr_id='$pHrId', 
                order_description='$pDesc', 
                order_tgl_awal='$pTglAwal',
                order_tgl_akhir='$pTglAkhir',
                order_date=trunc(sysdate), 
                order_for='$pOrderFor',
                ORDER_ATASAN_ID='$pAtasanId',
                ORDER_ATASAN_APP='$pAtasanApp',
                ORDER_ATASAN_APP_DATE=sysdate
            where order_id='$pOrderId'
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    
    function orderSelect1(){
        $sql 	= "
            select order_det_id
            from fm_order_detail
            where rownum=1
            order by order_det_id desc  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function orderInsertItem($pOrderId,$pWareItemId,$pWareItemName,$pQty,$nextId){  
        /*set order_id='$pOrderId', 
                order_det_id='$pDesc', 
                warehouse_name='$pTglAwal',
                warehouse_id='$pTglAkhir',
                order_det_qty=trunc(sysdate), 
                order_det_STATUS='$pOrderFor'*/
        $sql 	= "
            insert into fm_order_detail 
			     (order_id, order_det_id,warehouse_name, warehouse_id, order_det_qty, order_det_STATUS) 
            values 
			     ('$pOrderId', '$nextId', '$pWareItemName', '$pWareItemId', '$pQty',  'Y') 
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    function orderUpdateItem($pOrderId,$pWareItemId,$pQty){  
        /*set order_id='$pOrderId', 
                order_det_id='$pDesc', 
                warehouse_name='$pTglAwal',
                warehouse_id='$pTglAkhir',
                order_det_qty=trunc(sysdate), 
                order_det_STATUS='$pOrderFor'*/
        $sql 	= "
            update fm_order_detail 
            set order_det_qty='$pQty'   
            where order_id='$pOrderId'
                and warehouse_id='$pWareItemId'
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    function orderUpdateItemOther($pOrderId,$pOtherId,$pOtherName){  
        /*order_id, order_det_id,
                                   , warehouse_id, 
								   , */
        $sql 	= "
            update fm_order_detail 
            set warehouse_name='$pOtherName',
               order_det_qty=0,
               order_det_STATUS='Y'
            where order_id='$pOrderId'
                and warehouse_id='$pOtherId'
        ";    
        echo $sql; //exit;         
        $query = $this->db->query($sql);
    }
    
    //ORDER EQUIPMENT EDIT SAVE===========================END================================================

//-----------------------------------------------------------SERVICES END---------------------------------------------------------------------------------
    //REQUEST GA START===================================
    function getDetailPrintAcc($pCtrlID){
        $sql 	= "
                select hr2.NAME as ATASANNAME,
                tabelUtama.*
                from(    
                    
                    select control.USRUPD,
    				       hr.NAME,
    				       hr.ORG,
    				       hr.JOB_POSITION,
    					   hr.MSISDN,
    				       (select count(*)
    				        from FM_CONTROL_CARD card
    				        where card.ctrl_id = control.ctrl_id) iscard,
    				       (select count(*)
    				        from FM_CONTROL_TELP telp
    				        where telp.ctrl_id = control.ctrl_id) istelp,
    				       case when (select card.ctrl_card_user_type from FM_CONTROL_CARD card where card.ctrl_id = control.ctrl_id) is null then 
    				                 (select telp.ctrl_telp_user_type from FM_CONTROL_TELP telp where telp.ctrl_id = control.ctrl_id) else
    				                 (select card.ctrl_card_user_type from FM_CONTROL_CARD card where card.ctrl_id = control.ctrl_id) end as use_for,
    				       case when (select card.ctrl_card_vendor from FM_CONTROL_CARD card where card.ctrl_id = control.ctrl_id) is null then 
    				                 (select telp.ctrl_telp_vendor from FM_CONTROL_TELP telp where telp.ctrl_id = control.ctrl_id) else
    				                 (select card.ctrl_card_vendor from FM_CONTROL_CARD card where card.ctrl_id = control.ctrl_id) end as vendor,
    				       case when (select card.ctrl_card_user from FM_CONTROL_CARD card where card.ctrl_id = control.ctrl_id) is null then 
    				                 (select telp.ctrl_telp_user from FM_CONTROL_TELP telp where telp.ctrl_id = control.ctrl_id) else
    				                 (select card.ctrl_card_user from FM_CONTROL_CARD card where card.ctrl_id = control.ctrl_id) end as user_name,
    				       to_char(control.DTMUPD,'dd/mm/yyyy') as DTMUPD,
    				       control.CTRL_DESCRIPTION,
    					   to_char(control.CTRL_DATE_AWAL,'dd/mm/yyyy') as CTRL_DATE_AWAL,
    					   to_char(control.CTRL_DATE_AKHIR,'dd/mm/yyyy') as CTRL_DATE_AKHIR,
    					   control.CTRL_HOUR_AWAL,
    					   control.CTRL_HOUR_AKHIR,
    					   control.ctrl_atasan_id,
    					   control.CTRL_TELP_FISIK,
    					   control.CTRL_CARD_FISIK,
    					   control.CTRL_COMMENT_GA
    				from FM_ACCESS_CONTROL control inner join hrs hr
    				                               on hr.ID = control.USRUPD
    				where control.CTRL_ID = '$pCtrlID'  
                    
                    
                ) tabelUtama
                LEFT JOIN hrs hr2
                    ON hr2.ID=tabelUtama.CTRL_ATASAN_ID 
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetailPrintAccFloor($pCtrlID){
        $sql 	= "
                select cardflor.CARD_FLOOR_NAME
				from fm_access_control acces 
                inner join fm_control_card cardcon
				    on acces.CTRL_ID = cardcon.CTRL_ID
				inner join CONTROL_CARD_FLOOR cardflor
				    on cardcon.CTRL_CARD_ID = cardflor.CRTL_CARD_ID
				where acces.CTRL_ID = '$pCtrlID'
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetailPrintAccTelp($pCtrlID){
        $sql 	= "
                select telpext.TELP_EXT_EXT_TYPE
				from fm_access_control acces inner join fm_control_telp telpcon
				    on acces.CTRL_ID = telpcon.CTRL_ID
				inner join CONTROL_TELP_EXT telpext
				    on telpcon.CTRL_TELP_ID = telpext.CRTL_TELP_ID
				where acces.CTRL_ID = '$pCtrlID'
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //ACCESS CONTROL END=====================================
    //REQUEST GA START===================================
    function getDetailPrintReq($pReqId){
        $sql 	= "
                select hr2.NAME as ATASANNAME,
                        hr3.NAME as NIKNAME,
                        hr3.ORG as NIKORG,
                        hr3.JOB as NIKJOB,
                        hr3.JOB_POSITION as NIKJOBPOSITION,
                tabelUtama.*
                from(    
                    
                    select req_id, req_date, req_description, req_nik, req_untuk_nik, req_atasan_nik, req_info_hrd, req_floor, req_rbf_id, req_budget_ga 
                    from fm_req_head 
                    where req_id='$pReqId' 
                    
                    
                ) tabelUtama
                LEFT JOIN hrs hr2
                    ON hr2.ID=tabelUtama.REQ_ATASAN_NIK
                LEFT JOIN hrs hr3
                    ON hr3.ID=tabelUtama.REQ_UNTUK_NIK  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //REQUEST GA END=====================================
    //OVERTIME START===================================
    function getDetailPrintOvt($pSoId){
        $sql 	= "
                select hr2.NAME as ATASANNAME,
                        hr3.NAME as NIKNAME,
                        hr3.ORG as NIKORG,
                        hr3.JOB as NIKJOB,
                        hr3.JOB_POSITION as NIKJOBPOSITION,
                tabelUtama.*
                from(    
                    
                    select so_untuk_nik, so_nip, to_char(so_sdate,'dd/mm/yyyy') so_sdate, to_char(so_edate,'dd/mm/yyyy') so_edate, 
                        substr(so_shour,1,2) so_shours, substr(so_shour,4,2) so_ehours, so_comment, 
                        substr(so_ehour,1,2) so_shoure, substr(so_ehour,4,2) so_ehoure, so_description, so_ac, 
                        so_lift, so_lighting, so_other, so_other_description, so_atasan_nik from fm_So where so_id='$pSoId' 
                    
                    
                ) tabelUtama
                LEFT JOIN hrs hr2
                    ON hr2.ID=tabelUtama.SO_ATASAN_NIK
                LEFT JOIN hrs hr3
                    ON hr3.ID=tabelUtama.SO_UNTUK_NIK  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    
    function getDetailPrintOvtPhone($zUntukNik){
        $sql 	= "
                select msisdn 
                from hrs 
                where id='$zUntukNik'  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    
    function getDetailPrintOvtName($pSoId){
        $sql 	= "
                select sod_id, sod_name, so_id, sod_floor, sod_location, sod_vendor_id, sod_vendor_name 
                from fm_so_det 
                where so_id='$pSoId'  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //OVERTIME END=====================================
    //REPAIR MAINTENANCE START===================================
    function getDetailPrintRm($pRmID){
        $sql 	= "
                select hr2.NAME as ATASANNAME,
                tabelUtama.*
                from(    
                    
                    SELECT rm.rm_id, rm.rm_date, 
        			       rm.rm_type, rm.rm_category, 
        			       rm.rm_vendor, rm.rm_atasan_app, rm.rm_atasan_id,
        			       rm.rm_ga_app, rm.rm_floor,
        				   rm.RM_DESCRIPTION,
        				   rm.RM_SERIAL,
        				   rm.RM_SUITE,
        				   rm.RM_SHOUR,
        				   rm.RM_SMINUTE,
        				   rm.RM_EHOUR,
        				   rm.RM_EMINUTE,
        				   rm.RM_COMMENT_GA,
        				   to_char(rm.RM_RETURN,'DD/MM/YYYY') as RM_RETURN,
        				   to_char(rm.RM_DELIVERY,'DD/MM/YYY') as RM_DELIVERY,
        				   hr.id,
        				   hr.NAME,
        				   hr.ORG,
        				   hr.JOB_POSITION,
        				   hr.MSISDN
        			FROM fm_rm rm inner join hrs hr
        						  on rm.RM_NIP = hr.id
        			WHERE rm.rm_id = '$pRmID'
                    
                    
                ) tabelUtama
                LEFT JOIN hrs hr2
                    ON hr2.ID=tabelUtama.RM_ATASAN_ID  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //REPAIR MAINTENANCE END=====================================
    //SURAT IJIN KERJA START===================================
    function getDetailPrintSik($pSikId){
        $sql 	= "
                select hr2.NAME as ATASANNAME,
                        hr3.NAME as NIKNAME,
                        hr3.ORG as NIKORG,
                        hr3.JOB as NIKJOB,
                        hr3.JOB_POSITION as NIKJOBPOSITION,
                tabelUtama.*
                from(    
                    
                    select a.sik_untuk_nik, a.sik_atasan_nik, a.sik_id, 
                        a.sik_nik, to_char(a.sik_sdate,'dd/mm/yyyy') sik_sdate, to_char(a.sik_edate,'dd/mm/yyyy') sik_edate, 
                        a.vendor_id, a.mst_floor_id, b.vendor_name, a.vendor_pic, 
                        substr(sik_shour,1,2) shours, substr(sik_shour,4,2) ehours, sik_ga_comment, 
                        substr(sik_ehour,1,2) shoure, substr(sik_ehour,4,2) ehoure, a.vendor_jabatan 
                    from fm_sik a, lkk_vendor_mst b 
                    where a.vendor_id = b.vendor_id and a.sik_id='$pSikId'
                    
                    
                ) tabelUtama
                LEFT JOIN hrs hr2
                    ON hr2.ID=tabelUtama.SIK_ATASAN_NIK
                LEFT JOIN hrs hr3
                    ON hr3.ID=tabelUtama.SIK_UNTUK_NIK  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    
    function getDetailPrintSikPhone($aUntukNik){
        $sql 	= "
                select msisdn 
                from hrs 
                where id='$aUntukNik'  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    
    function getDetailPrintSikName($pSikId){
        $sql 	= "
                select * 
                from fm_sik_job 
                where sik_id='$pSikId' 
                order by sikj_id asc  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //SURAT IJIN KERJA END=====================================
    //LOT PARKIR START===================================
    function getDetailPrintPrk($pParkirdId){
        $sql 	= "
                select hr2.NAME as ATASANNAME,
                        hr3.NAME as NIKNAME,
                        hr3.ORG as NIKORG,
                        hr3.JOB as NIKJOB,
                        hr3.JOB_POSITION as NIKJOBPOSITION,
                tabelUtama.*
                from(    
                    
                    select a.parkird_nik, a.parkird_untuk_nik, a.parkird_atasan_nik, a.parkird_type, a.parkird_plat, a.parkird_stnk, 
    			       a.parkird_date, a.parkird_description, a.parkird_file, a.parkird_use_by,  
    			       a.parkird_type_1, a.parkird_plat_1, a.parkird_stnk_1, a.parkird_flag_1, 
    			       a.parkird_type_2, a.parkird_plat_2, a.parkird_stnk_2, a.parkird_flag_2, 
    			       a.parkird_type_3, a.parkird_plat_3, a.parkird_stnk_3, a.parkird_flag_3, 
    			       to_char(b.contract_sdate,'dd/mm/yyyy') contract_sdate, to_char(b.contract_edate,'dd/mm/yyyy') contract_edate,
    				   a.parkird_comment, b.msisdn
    				from fm_parkir_det a, hrs b 
    				where a.parkird_untuk_nik = b.id and parkird_id='$pParkirdId'
                    
                    
                ) tabelUtama
                LEFT JOIN hrs hr2
                    ON hr2.ID=tabelUtama.PARKIRD_ATASAN_NIK
                LEFT JOIN hrs hr3
                    ON hr3.ID=tabelUtama.PARKIRD_UNTUK_NIK  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //LOT PARKIR END=====================================
    
    //PAGING INFO START===================================
    function getDetailPrintPag($pInfoId){
        $sql 	= "
                select hr2.NAME as ATASANNAME,
                        hr3.NAME as NIKNAME,
                        hr3.ORG as NIKORG,
                        hr3.JOB as NIKJOB,
                        hr3.JOB_POSITION as NIKJOBPOSITION,
                tabelUtama.*
                from(    
                    
                    select info_shour, info_sminute, info_repetition, 
                        info_keterangan, info_untuk_nik, info_atasan_nik, info_id, info_nik, 
                        to_char(info_sdate,'dd/mm/yyyy') info_sdate, info_subject, info_description 
                    from fm_paging_info 
                    where info_id='$pInfoId'
                    
                    
                ) tabelUtama
                LEFT JOIN hrs hr2
                    ON hr2.ID=tabelUtama.INFO_ATASAN_NIK
                LEFT JOIN hrs hr3
                    ON hr3.ID=tabelUtama.INFO_UNTUK_NIK  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //PAGING INFO END=====================================
    //SARAN KELUHAN START===================================
    function getDetailPrintSarKel($pPoboxId){
        $sql 	= "
                select hr2.NAME as ATASANNAME,
                        hr3.NAME as NIKNAME,
                        hr3.ORG as NIKORG,
                        hr3.JOB as NIKJOB,
                        hr3.JOB_POSITION as NIKJOBPOSITION,
                tabelUtama.*
                from(    
                    
                    select a.pobox_relatedto, a.pobox_atasan_nik, a.pobox_id, 
                        a.pobox_nip, a.pobox_untuk_nik, a.pobox_type, 
                        a.pobox_subject, a.pobox_description, a.type_id, b.mst_type_desc, 
                        a.pobox_ga_app_follow 
                    from fm_pobox a, fm_mst_type b 
                    where a.type_id = b.mst_type_id and a.pobox_id='$pPoboxId'
                    
                    
                ) tabelUtama
                LEFT JOIN hrs hr2
                    ON hr2.ID=tabelUtama.POBOX_ATASAN_NIK
                LEFT JOIN hrs hr3
                    ON hr3.ID=tabelUtama.POBOX_UNTUK_NIK  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetailPrintSarKelPhone($aPoboxUntukNik){
        $sql 	= "
                select msisdn 
                from hrs 
                where id='$aPoboxUntukNik' 
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetailPrintSarKelCrit($zMstTypeId){
        $sql 	= "
                select * 
                from fm_mst_type 
                where mst_type_id = '$zMstTypeId'
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //SARAN KELUHAN END=====================================
    //ORDER EQUIPMENT START===================================
    function getDetailPrintOrder($pOrderId){
        $sql 	= "
                select hr2.NAME as HRNAME,
                        hr2.ORG as HRORG,
                        hr2.JOB as HRJOB,
                        hr2.JOB_POSITION as HRJOBPOSITION,
                        hr3.NAME as OFNAME,
                        hr3.ORG as OFORG,
                        hr3.JOB as OFJOB,
                        hr3.JOB_POSITION as OFJOBPOSITION,
                tabelUtama.*
                from(    
                    
                    SELECT A.ORDER_DESCRIPTION, TO_CHAR(A.ORDER_TGL_AWAL,'dd/mm/yyyy') order_tgl_Awal, 
                            to_char(A.ORDER_TGL_AKHIR,'dd/mm/yyyy') order_tgl_akhir, 
                            A.HR_ID, A.ORDER_FOR, A.ORDER_DATE, A.ORDER_GA_COMMENT
                    FROM FM_ORDER_HEADER A 
                    WHERE A.ORDER_ID = '$pOrderId'
                    
                    
                ) tabelUtama
                LEFT JOIN hrs hr2
                    ON hr2.ID=tabelUtama.HR_ID
                LEFT JOIN hrs hr3
                    ON hr3.ID=tabelUtama.ORDER_FOR  
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetailPrintOrderPhone($aOrderFor){
        $sql 	= "
                select msisdn 
                from hrs 
                where id='$aOrderFor' 
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetailPrintOrderName($pOrderId){
        $sql 	= "
                select * 
                from fm_order_detail 
                where order_id='$pOrderId'
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //ORDER EQUIPMENT END=====================================
    //MEETING ROOM START===================================
    function getDetailPrintMeet($pRoomId){
        $sql 	= "
                    select room.ROOM_FLOOR,
        			       room.ROOM_JENIS,
        			       room.ROOM_TYPE,
        			       to_char(room.ROOM_DATE,'dd/MM/yyyy') as ROOM_DATE,
        			       room.ROOM_SHOUR||':'||room.ROOM_SMINUTE as Star_hour,
        			       room.ROOM_EHOUR||':'||room.ROOM_EMINUTE as End_hour,
        			       room.ROOM_DESCRIPTION,
        			       room.ROOM_PARTICIPANT,
        			       room.ROOM_CONDITION,
        			       room.ROOM_COMMENT_GA,
        			       hr.ID,
        			       hr.NAME,
        			       hr.ORG,
        			       hr.JOB_POSITION
        			from fm_meeting_room room left join hrs hr
        			                          on room.ROOM_UNTUK_NIK = hr.ID
        			where room.room_id = '$pRoomId' 
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    function getDetailPrintMeet2($pRoomId){
        $sql 	= "
                select det.roomd_description,
				        det.roomd_qty,
				        (select nvl(house.WAREHOUSE_ITEM_QTY_IN,0)
				            from FM_WAREHOUSE house
				            where det.WAREHOUSE_ID = house.WAREHOUSE_ID) as WAREHOUSE_ITEM_QTY_IN,
                        det.ROOMD_ID
                from FM_MEETING_ROOM_DET det
				where det.room_id = '$pRoomId'
				        and det.ROOMD_STATUS = 'Y'
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //MEETING ROOM END=====================================
    //MAILLING ROOM START===================================
    function getDetailPrintMail($pDmrID){
        //QUERY ORI TIDAK DIGUNAKAN UNTUK MENGANTISIPASI SAAT DATABASE LOKAL TIDAK ADA DATANYA, GUNAKAN SAJA LEFT JOIN UNTUK MENDAPATKAN DATA HRS    
        /*$sql 	= "
                    select hr.id,
    				       hr.NAME,
    				       hr.ORG,
    				       hr.JOB_POSITION,
    					   hr.msisdn,
    				       dmr.DMR_COURIER_TYPE,
    				       (select area.area_name||' - '||area.regional_name
    				        from FM_MST_AREA area
    				        where area.area_name = dmr.DMR_TUJUAN and area.regional_name=dmr.dmr_regional) DMR_TUJUAN,
    				       dmr.DMR_PENJEMPUTAN,
    				       dmr.DMR_FLOOR,
    				       dmr.DMR_TYPE,
    				       dmr.DMR_CATEGORY,
    				       dmr.DMR_WAKTU_PENJEMPUTAN,
    				       dmr.DMR_DESCRIPTION,
    					   dmr.DMR_ATASAN_APP_ID,
    					   to_char(dmr.DMR_RECIEVE_DATE,'DD/MM/YYYY') as DMR_RECIEVE_DATE,
    					   dmr.DMR_REGIONAL
    			   from FM_DMR dmr inner join hrs hr
    				                on dmr.HR_ID = hr.ID 
    			   where dmr.DMR_ID = '$pDmrID'
        ";
        */    
        $sql 	= "
                select hr2.NAME as ATASANNAME,
                tabelUtama.*
                from(    
                    
                        select hr.id,
        				       hr.NAME,
        				       hr.ORG,
        				       hr.JOB_POSITION,
        					   hr.msisdn,
        				       dmr.DMR_COURIER_TYPE,
        				       (select area.area_name||' - '||area.regional_name
        				        from FM_MST_AREA area
        				        where area.area_name = dmr.DMR_TUJUAN and area.regional_name=dmr.dmr_regional) DMR_TUJUAN,
        				       dmr.DMR_PENJEMPUTAN,
        				       dmr.DMR_FLOOR,
        				       dmr.DMR_TYPE,
        				       dmr.DMR_CATEGORY,
        				       dmr.DMR_WAKTU_PENJEMPUTAN,
        				       dmr.DMR_DESCRIPTION,
        					   dmr.DMR_ATASAN_APP_ID,
        					   to_char(dmr.DMR_RECIEVE_DATE,'DD/MM/YYYY') as DMR_RECIEVE_DATE,
        					   dmr.DMR_REGIONAL
        			   from FM_DMR dmr 
                       left join hrs hr
                            on dmr.HR_ID = hr.ID 
        			   where dmr.DMR_ID = '$pDmrID'
                    
                    
                ) tabelUtama
                LEFT JOIN hrs hr2
                    ON hr2.ID=tabelUtama.DMR_ATASAN_APP_ID
        ";    
        //echo $sql; //exit;         
        $query = $this->db->query($sql);
        return $query->result_array();
    }
    //MAILLING ROOM END=====================================
    
    
//------------------------------------------------------------PRINT START---------------------------------------------------------------------------------

//------------------------------------------------------------PRINT END----------------------------------------------------------------------------------- 
    //
    function hitungAja(){
        $sql 	= "
        select count(*) CNT
		      from hrs 
        ";
        //echo $sql; exit;        
        $query = $this->db->query($sql);
        return $query->result_array();
    }
}
?>